![]() ![]() If you’re working on i2c devices to any extent, I suggest you stash this code away somewhere: it makes a very useful tool, not only to check if devices are visible, but also to troubleshoot troublesome devices with addresses that aren’t Google-able. The common point is that you need to see if the device is responding to a poll for its address – this proves its alive, and you can use the address to get your code running for that sensor//display. ![]() Some hacks to get 5V devices working in 3.3V systems, and visa-versa, are possible, but again: another guide. ![]() In the case of Raspberry Pi, you’ll be using a 3.3V system. You’ll use the following code with an Arduino UNO or such to use as a tool to read the address of the connected sensor at 5V, as most sensors designed for Arduino run at 5V. In the setup, the LCD is initiated with lcd.init() and the backlight is turned on with lcd.backlight().Sniffing around for i2c on Raspberry Pi is a bit different, and is for another guide, but the basic principle is the same. Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered) You will need to change ‘lcd’ to the new name in the rest of the sketch. You can give it a different name if you want like ‘menu_display’. Note that we have called the display ‘lcd’. When using a 20×4 LCD, change this line to LiquidCrystal_I2C(0x27,20,4) This is where you will need to change the default address to the address you found earlier if it happens to be different. ![]() The next step is to create an LCD object with the LiquidCrystal_I2C class and specify the address and dimensions.įor this, we use the function LiquidCrystal_I2C(address, columns, rows). #include // Library for I2C communication The other library imports wire.h automatically. *When using the latest version of the LiquidCrystal_I2C library it is no longer needed to include the wire.h library in your sketch. In the rest of this tutorial, I will cover more of the built-in functions of this library. As mentioned earlier we need both the wire.h* and the LiquidCrystal_I2C library. First, the required libraries are included. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |