Using the Aardvark with Python on 64-bit Windows – Total Phase
Using the Aardvark with Python on 64-bit Windows

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

    1. Download and run the latest version of the Total Phase USB Drivers Installer.
    2. Download and unzip the latest version of Aardvark API for Windows 64-bit. (?)
    3. Connect the Aardvark adapter to the PC via the USB connector.
    4. Install Python 2.x for Windows 64 bit from the Python website.
      1. These guidelines use the default Python installation location of "C:\Python27".
    5. Verify the Aardvark API examples setup is correct.
      1. Be sure to use 64-bit Python when you use the 64-bit version of the the Aardvark API.
      2. Be sure to have the aardvark.dll file in same directory as the Python examples as provided in the API package.
    6. Run the original aadetect Python example as provided in the API package.
      1. Open Command Prompt. (?)
      2. Change to the Aardvark API Python directory by typing: cd C:\...\python
      3. Run the detect example by typing: C:\Python27\python.exe aadetect.py
      4. Verify that the computer detects the Aardvark adapter.

    1. Connect the Aardvark adapter to the I2C/SPI activity board via the I2C/SPI connector. (?)
    2. 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.
        1. Open Command Prompt. (?)
        2. Change to the Aardvark API Python directory ("...\python”).
        3. 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.
        4. 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.
        5. Verify that the Aardvark adapter writes and reads the I2C data correctly.

    1. 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.
        1. Open Command Prompt. (?)
        2. Change to the Aardvark API Python directory ("...\python”).
        3. 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.
        4. 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.
        5. 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.

Have more questions? Submit a request