Introduction
Transferring I2C/SPI data with Aardvark API is a common use case for the Aardvark Adapter. The Aardvark API supports multiple operating systems (Windows, Linux, and Mac) and multiple languages (C, Python, Visual Basic, and C#), and includes examples. The user can use the Aardvark API to control the Aardvark adapter, and to write a custom program to achieve his goals. For new users, Total Phase recommends to use the Python language as it is a simple language, and a good option for scripting. This article focuses on how to install the Aardvark API, and run a few of the original API Python examples. Although the following describes transferring I2C/SPI data to the Atmel I2C EEPROM AT24C02 and Atmel SPI EEPROM AT25080A found on the I2C/SPI activity board, similar steps can be used for other I2C/SPI devices.
Overview
This article describes three Aardvark API Python examples: aadetect, aai2c_eprom, and aaspi_eeprom.
- aadetect example - Displays the port numbers for the connected Aardvark adapters.
- aai2c_eeprom example - Read or write I2C data from the I2C EEPROM on the activity board. The example parameters are: PORT, BITRATE, write/read/zero, SLAVE_ADDR, OFFSET, and LENGTH. You can see this example's available parameters by running the example without arguments. In this example, the Aardvark adapter is the I2C master and the Atmel I2C EEPROM AT24C02 on the I2C/SPI activity board is the I2C slave. In the guidelines below, the first operation writes 4 bytes to the I2C EEPROM with I2C slave address 0x50 at offset address 0x02 with bitrate 100 KHz. Then the 4 bytes are read from the same offset.
- aaspi_eeprom example - Read or write SPI data from the SPI EEPROM on the activity board. The example parameters are: PORT, BITRATE, write/read/zero, MODE, ADDR, and LENGTH. You can see this example's available parameters by running the example without arguments. In this example, the Aardvark adapter is the SPI master and the Atmel SPI EEPROM AT25080A on the I2C/SPI activity board is the SPI slave. In the guidelines below, the first operation writes 4 bytes to the SPI EEPROM at offset address 0x02 with bitrate 100 KHz and SPI mode 0. Then the 4 bytes are read from the same offset.
API Python Installation Guidelines
- Download and run the latest version of the Total Phase USB Drivers Installer.
- Download and unzip the latest version of Aardvark API for Windows 64-bit. (?)
- Connect the Aardvark adapter to the PC via the USB connector.
- Install Python 2.x for Windows 64 bit from the Python website.
- These guidelines use the default Python installation location of "C:\Python27".
- Verify the Aardvark API examples setup is correct.
- Be sure to use 64-bit Python when you use the 64-bit version of the the Aardvark API.
- Be sure to have the aardvark.dll file in same directory as the Python examples as provided in the API package.
- Run the original aadetect Python example as provided in the API package.
- Open Command Prompt. (?)
- Change to the Aardvark API Python directory by typing: cd C:\...\python
- Run the detect example by typing: C:\Python27\python.exe aadetect.py
- Verify that the computer detects the Aardvark adapter.
- Connect the Aardvark adapter to the I2C/SPI activity board via the I2C/SPI connector. (?)
- Write and read from the Atmel I2C EEPROM AT24C02 that in the Total Phase I2C/SPI activity board with Aardvark adapter and Aardvark API Python original example aai2c_eeprom.
- Open Command Prompt. (?)
- Change to the Aardvark API Python directory ("...\python”).
- Run the writing option of the aai2c_eeprom example by typing: C:/Python27/python.exe aai2c_eeprom.py 0 100 write 0x50 2 4. This command writes 4 bytes from Aardvark at port 0 to slave address 0x50 at offset address 0x02 with bitrate 100 KHz.
- Run the reading option of the aai2c_eeprom example by typing: C:/Python27/python.exe aai2c_eeprom.py 0 100 read 0x50 2 4. This command reads 4 bytes to Aardvark at port 0 from slave address 0x50 at offset address 0x02 with bitrate 100 KHz.
- Verify that the Aardvark adapter writes and reads the I2C data correctly.
- Write and read from the Atmel SPI EEPROM AT25080A that in the Total Phase I2C/SPI activity board with Aardvark adapter and Aardvark API Python original example aaspi_eeprom.
- Open Command Prompt. (?)
- Change to the Aardvark API Python directory ("...\python”).
- Run the writing option of the aaspi_eeprom example by typing: C:/Python27/python.exe aaspi_eeprom.py 0 100 write 0 2 4. This command writes 4 bytes from Aardvark port 0 to memory in address 0x2 with bitrate 100 KHz and mode 0.
- Run the reading option of the aaspi_eeprom example by typing: C:/Python27/python.exe aaspi_eeprom.py 0 100 read 0 2 4. This command reads 4 bytes to Aardvark port 0 from memory in address 0x2 with bitrate 100 KHz and mode 0.
- Verify that the Aardvark adapter writes and reads the SPI data correctly.
Notes
For additional information, take a look at the Aardvark adapter user manual, Aardvark API documentation and I2C/SPI activity board manual.