# Python Programming using MRAA (Aio)



1. Targeted Hardware   &#x20;

SOM Version: PICM-001-A1

CB : RuggedBoard-A5D2X

CB Version : RB-A5D2X-V1.1

&#x20;   2.Targeted Software   &#x20;

BSP-Yocto-A5D2X 2019-03-13

* AT91Bootstrap-3.8.12
* Linux Kernel v4.9.151
* uboot-2018-07
* Yocto 2.5.2 (sumo HEAD commit 623b77885051)

Description

* Connect a pot(potentiometer) to rugged board a5d2x

Required Hardware

* a5d2x-rugged board
* USB cable
* potentiometer

Step-by-step guide

* Connect the Pot (it will have three patch codes(wires)), center one connect to "AN" (analog pin) of mikro bus connector.
* The remaining two you can connect one to ground (pin 60) & one to vcc (pin 01) on expansion header respectively.
* Connect the Rugged board to your system
* Boot the board with SD card/NOR.
* Copy the below python file to data directory of rugged board through tftp protocol.

1. Test aio.py with the help of potentiometer
2. Open aio.py program given below in your board terminal.
3. Open the aio.py program in /data directory.

PROGRAM: aio.py

```
import mraa
print(mraa.getVersion())

try:

# initialise AIO
x = mraa.Aio(6)

# read integer value
print(x.read())

# read float value
print("%.5f" % x.readFloat())
except: print("Are you sure you have an ADC?")
```

Execution :

Run the above code with below command in rugged board.

root@ruggedboard-a5d2x:/data# python3 aio.py

Expected Output

root@ruggedboard-a5d2x:/data# python3 aio.py&#x20;

random: python3: uninitialized urandom read (24 bytes read)                                                                libmraa\[128]: libmraa version v2.0.0 initialised by user 'root' with EUID 0 libmraa\[128]: gpio: platform doesn't support chardev, falling back to sysfs libmraa\[128]: libmraa initialised for platform 'Atmel SAMA5' of type 20 v2.0.0&#x20;

ADC A0 read 1FD - 509

ADC A0 read float - 0.49560

ADC A0 read 1FC - 508

&#x20;ADC A0 read float - 0.49560&#x20;

ADC A0 read 1FC - 508

&#x20;ADC A0 read float - 0.49658&#x20;

ADC A0 read 1FD - 509

&#x20;ADC A0 read float - 0.49560

&#x20;ADC A0 read 1FA - 506

&#x20;ADC A0 read float - 0.49756&#x20;

ADC A0 read 1FB - 507

&#x20;ADC A0 read float - 0.49560

&#x20;ADC A0 read 1FB - 507

&#x20;ADC A0 read float - 0.49462&#x20;

ADC A0 read 1FA - 506&#x20;

ADC A0 read float - 0.49462

&#x20;ADC A0 read 1FB - 507&#x20;

ADC A0 read float - 0.49756

&#x20;ADC A0 read 1FC - 508&#x20;

ADC A0 read float - 0.49658&#x20;

ADC A0 read 1FD - 509

&#x20;ADC A0 read float - 0.49560

&#x20;ADC A0 read 1FB - 507

&#x20;ADC A0 read float - 0.49462&#x20;

ADC A0 read 1FB - 507

&#x20;ADC A0 read float - 0.49756

&#x20;ADC A0 read 1FE - 510&#x20;

ADC A0 read float - 0.49462&#x20;

ADC A0 read 1FD - 509&#x20;

ADC A0 read float - 0.49365&#x20;

ADC A0 read 1FB - 507

&#x20;ADC A0 read float - 0.49560

&#x20;ADC A0 read 1FB - 507

&#x20;ADC A0 read float - 0.49462&#x20;

ADC A0 read 1FA - 506

&#x20;ADC A0 read float - 0.49560

&#x20;ADC A0 read 1FA - 506&#x20;

ADC A0 read float - 0.49658

&#x20;ADC A0 read 1FA - 506&#x20;

ADC A0 read float - 0.49462

&#x20;ADC A0 read 1F9 - 505

&#x20;ADC A0 read float - 0.49658

&#x20;ADC A0 read 1FC - 508

&#x20;ADC A0 read float - 0.49462&#x20;

ADC A0 read 1FB - 507&#x20;

ADC A0 read float - 0.49560&#x20;

ADC A0 read 1FA - 506

&#x20;ADC A0 read float - 0.49365&#x20;

ADC A0 read 1F2 - 498&#x20;

ADC A0 read float - 0.48680&#x20;

ADC A0 read 1F0 - 496&#x20;

ADC A0 read float - 0.48485&#x20;

ADC A0 read 1EF - 495

&#x20;ADC A0 read float - 0.48387&#x20;

ADC A0 read 1F2 - 498&#x20;

ADC A0 read float - 0.48680

&#x20;ADC A0 read 1F0 - 496

&#x20;ADC A0 read float - 0.48680&#x20;

ADC A0 read 1F2 - 498

&#x20;ADC A0 read float - 0.48778

&#x20;ADC A0 read 1F0 - 496

&#x20;ADC A0 read float - 0.48583

&#x20;ADC A0 read 1F2 - 498

&#x20;ADC A0 read float - 0.48680

&#x20;ADC A0 read 1F0 - 496

&#x20;ADC A0 read float - 0.48680

&#x20;ADC A0 read 1F0 - 496

&#x20;ADC A0 read float - 0.48583

&#x20;ADC A0 read 1F1 - 497&#x20;

ADC A0 read float - 0.48485&#x20;

ADC A0 read 1F0 - 496

&#x20;ADC A0 read float - 0.48387&#x20;

ADC A0 read 1EF - 495&#x20;

ADC A0 read float - 0.48387&#x20;

ADC A0 read 1F2 - 498

&#x20;ADC A0 read float - 0.48485

&#x20;ADC A0 read 1F1 - 497

&#x20;ADC A0 read float - 0.48485

&#x20;ADC A0 read 1F3 - 499

&#x20;ADC A0 read float - 0.48680







