Exploring Raspberry Pi by Derek Molloy

Exploring Raspberry Pi by Derek Molloy

Author:Derek Molloy
Language: eng
Format: mobi, epub
ISBN: 9781119188698
Published: 2016-05-31T00:00:00+00:00


I2C AND WIRINGPi

The wiringPi library that is installed in Chapter 6 has a library of C functions for interacting with I2C bus devices. This short code example reads the first three registers from the DS3231 RTC and displays the current time:

pi@erpi ~/exploringrpi/chp08/i2c/wiringPi $ more DS3231.c #include<wiringPiI2C.h> #include<stdio.h> int main(){ int fd = wiringPiI2CSetup(0x68); int secs = wiringPiI2CReadReg8(fd, 0x00); int mins = wiringPiI2CReadReg8(fd, 0x01); int hours = wiringPiI2CReadReg8(fd, 0x02); printf("The RTC time is %2d:%02d:%02d\n", hours, mins, secs); return 0; } pi@erpi ~/exploringrpi/chp08/i2c/wiringPi $ gcc DS3231.c -o rtc -lwiringPi pi@erpi ~/exploringrpi/chp08/i2c/wiringPi $ ./rtc The RTC time is 10:08:83

There is more information on this library at tiny.cc/erpi804. Be aware that this library is written specifically for the RPi platform; it will not work on other embedded Linux devices that do not contain the same SoC.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.