Ligne 18 : |
Ligne 18 : |
| | | |
| == Utilisation logicielle == | | == Utilisation logicielle == |
− | To use I2C with the Adafruit Python GPIO library you'll need to create an '''Adafruit_FT232.I2CDevice''' instance. This object takes as a parameter to its initializer the FT232H object that represents your FT232H chip, and the address of the I2C device to communicate with using the chip.
| + | Pour utiliser le bus I2C avec la bibliothèque Adafruit Python GPIO, il sera nécessaire de créer une instance de la classe '''Adafruit_FT232.I2CDevice'''. Cet objet prend en paramètre l'objet FT232H et l'adresse du périphérique I2C avec lequel le FT232H va communiquer. |
| | | |
− | For example the code below creates an I2C device for a device with address 0x70:
| + | Par exemple, le code suivant crée un périphérique I2C pour communiquer avec un périphérique I2C ayant l'adresse 0x70: |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
| import Adafruit_GPIO.FT232H as FT232H | | import Adafruit_GPIO.FT232H as FT232H |
| | | |
− | # Temporarily disable FTDI serial drivers. | + | # Désactive temporairement le pilote FTDI série. |
| FT232H.use_FT232H() | | FT232H.use_FT232H() |
| | | |
− | # Find the first FT232H device. | + | # Trouver le premier périphérique FT232H. |
| ft232h = FT232H.FT232H() | | ft232h = FT232H.FT232H() |
| | | |
− | # Create an I2C device at address 0x70. | + | # Créer un périphérique I2C (utilisant l'adresse 0x70). |
| i2c = FT232H.I2CDevice(ft232h, 0x70) | | i2c = FT232H.I2CDevice(ft232h, 0x70) |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | At this point the I2CDevice instance is ready for reading and writing simple 8 and 16 bit values from registers. The interface on the I2CDevice class for reading and writing is exactly the same as the [https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_I2C/Adafruit_I2C.py interface on the Raspberry Pi Python I2C code], so you can examine code which is written for the Pi and use it with very few changes on the FT232H.
| + | A ce point, l'instance de la classe I2CDevice est prête à lire et écrire des valeurs 8 et 16 bits depuis/dans les registres. L'interface de la classe I2CDevice permettant de lire et écrire des données est exactement la même que [https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_I2C/Adafruit_I2C.py l'interface Python I2C code pour Raspberry Pi]. Cela permet d'adapter très facilement le code I2C pour Raspberry-Pi vers le breakout FT232H. |
| | | |
− | For example to read a 16 bit register value and write an 8 bit register value to the device the code might look like:
| + | Par exemple, pour lire la valeur d'un registre 16 bits et écrire une valeur dans un registre 8 bit, vous pourriez lire un code comme celui-ci: |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
− | # Read a 16 bit unsigned little endian value from register 0x01. | + | # Lecture d'un valeur 16 bit non-signé (little endian) depuis le registre 0x01. |
| response = i2c.readU16(0x01) | | response = i2c.readU16(0x01) |
| | | |
− | # Write a 8 bit value 0xAB to register 0x02. | + | # Ecrire une valeur 8 bits (0xAB) dans le registre 0x02. |
| i2c.write8(0x02, 0xAB) | | i2c.write8(0x02, 0xAB) |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | That's all there is to using I2C with the Adafruit Python GPIO library and the FT232H board!
| + | C'est tout ce qui nous avons besoin de savoir pour utiliser le bus I2C du FT232H à l'aide de la bibliothèque Adafruit Python GPIO! |
| | | |
− | You might also be interested in [https://learn.adafruit.com/adafruit-ft232h-with-spi-and-i2c-libraries this tutorial which shows how to use the FT232H breakout with some Adafruit I2C devices] that have been ported to use Adafruit's Python GPIO library.
| + | Vous pourriez également être intéressé dans le tutoriel [https://learn.adafruit.com/adafruit-ft232h-with-spi-and-i2c-libraries this tutorial which shows how to use the FT232H breakout with some Adafruit I2C devices] that have been ported to use Adafruit's Python GPIO library. |
| | | |
| == Autre bibliothèque I2C == | | == Autre bibliothèque I2C == |