more notes for a bad memory - - -
Setting up the Raspberry Pi with a working i2c bus
Objective
link to and control i2c devices
I have a long line to a cluster of i2c devices
One of the LM75 thermometers would not run all the time at the default baud rate of 100.000 Hz
many methods are offered via Google but none worked until I created a file :-
/etc/modprobe.d/i2c_speed.conf
containing
options i2c_bcm2708 baudrate=10000 - in the end I used a low speed - 10000 for my very long line
(but with Jessie - later - this was not needed
- just the config.txt add on below)
I also added
i2c-bcm2708
i2c-dev
to
/etc/modules
Not sure if these were needed - check next time - remove them 1 by 1 to see if they are active - getting i2c speed to change was a long ordeal!!
modprobe -r i2c_bcm2708
modprobe i2c_bcm2708 baudrate=10000
also, I have at the the end of boot/config.txt
dtparam=i2c_arm=on
dtparam=i2c0_baudrate=10000
also
/etc/init.d/graham_startup
contains
modprobe i2c_bcm2708
modprobe i2c_dev
# /etc/modules: kernel modules to load at boot time. snd-bcm2835 i2c-bcm2708 |
This is for a Mod B Pi
You can see the set speed in dmesg
The blassic code used for testing :-
#!/usr/sbin/blassic LABEL GoAgain 'read the LM75 thermometers on the panel and tanks ' bring the temperature values into blassic as strings PRINT "temperatures", T72$, T74$, T75$, T76$, T77$ 'build a test web page OPEN "/var/www/solar.html" FOR OUTPUT AS #1 : PRINT #1, "<html><head><META HTTP-EQUIV='refresh' CONTENT='5; URL=http://192.168.0.84/solar.html'></head><body><h1>Solar Hot Water</h1><p>Temperatures</p>" : CLOSE #1 PRINT "done" SYSTEM |
/* i2c_lm75.c int i2c; /* address is the first number after the program name */ i2c = open("/dev/i2c-0",O_RDWR); /* open the device dev/i2c-0 */ read(i2c,data,2); byte1 = data[0]; temperature = byte1*256+byte2; realtemp = (double)temperature / 2; i2c = close(i2c); |
The test web page created -
<html> <head> <META HTTP-EQUIV='refresh' CONTENT='5; URL=http://192.168.0.84/solar.html'> </head> <body> <h1>Solar Hot Water</h1> <p>Temperatures</p> 20.5 18.0 25.5 20.0 49.5 <BR> </body> </html>
Please email me if you want to swap notes
more to come . . .