index
NSLU2 as master driving a local PIC microprocessor as an i2c slave with attached
graphic display plotting A to D data from a remote PIC also acting as i2c slave


Objectives
Have a remote PIC 16F877A acting as i2c slave measuring voltages on its A to D lines - also switching port lines and detecting line states - this remote PIC to show data on a 4x20 character display

Have a PIC local to the master, also an i2c slave, driving a 64 x 128 graphic display that displays data measured by the remote PIC

Eventual application
Local in house display and control of remote greenhouse temperatures etc plus the ability to control remote heaters, windows etc and detect door/window states etc.


The 64 x 128 graphic display
is a QY-12864BG. It is a clone of the Hantronix HDM64GS12 with a KS0108 display controller

The i2c master is a NSLU2 (Slug) running Debian in this test - but it could be any i2c master device

These notes represent a first milestone that I need to record for future reference and backup of progress so far.
There is much yet to do (and some poor code!) but at least I now have a remote PIC reading data and a local PIC displaying the data on a 64 x 128 graphic display.

The Remote PIC runs 16F877_AD_rs232_LCD_i2c_5b.C
and the Slug runs PIC_i2c_one_ADnumber_only_a.c to control it

The Local PIC runs i2c_graphicLCD_1.C
and the Slug runs PIC_i2c_send_data_to_plot_ram.c to control it

The Slug calls the local C programs from a Blassic basic program
i2c_ad-remote_plot-local_1.bas


The PIC circuits are given below
- the MAX232 rs232 interface (5 volts only) has the same circuit as this (a MAX3232 works with 3.3 and 5 volts)
- the 82B715 i2c long line converter is included in this circuit
(there is no need for the i2c voltage converter FETs at the PIC end - only for the Slug)


Code notes
PIC_i2c_one_ADnumber_only_a - (used to control remote PIC)
It needs 7 arguments when called -
0 - remote PIC address
1 - x value - 0 for AD0, 2 for AD1, etc to AD7 - x=16,18,20,22 get D4,5,6,7 states as 0 or 1
2 - command 0 for admin display, 1 for temperatures
3 - 0 for D0 off (0 volts), 1 for D0 on (5volts)
4 - 0 for D1 off (0 volts), 1 for D1 on (5volts)
5 - 0 for D2 off (0 volts), 1 for D2 on (5volts)
6 - 0 for D3 off (0 volts), 1 for D3 on (5volts)
eg /home/graham/i2c/PIC_i2c_one_ADnumber_only_a 80 0 0 1 0 0 0 - read AD0, show admin, LED D4 on

PIC_i2c_send_data_to_plot_ram.c - (used to control local graphic display PIC)
It needs 11 arguments when calle
d
1 - PIC address (0xA2 is decimal 81)
2 - free
3 - number in master's data file to start reading (list_start)
- - - - - it sends these to PIC:-
4 - PIC display plot starting point on x axis
5 - number of data points sent to be displayed
6 - 1 - wipe this data area before plot, 0 - leave it for overwrite
7 - 1- we WILL plot some data points, 0 - might just switch lines etc (later)
8 - 1 - clear whole screen, 0 leave it alone
9 - free
10 - free
11 - free

eg /home/graham/i2c_ad-remote_plot-local/PIC_i2c_send_data_to_plot_ram 81 0 0 10 1 1 1 0 0 0 0
i2c address Linux decimal 81 / read Slug data file starting at zero / free / plot the data point at x = 10 / plot 1 point / wipe the prevous value / do plot the data / do not clear the whole screen / free / free / free /

Note - if you ask the local PIC to both read A to D values and drive a graphic display it crashes at random times - perhaps some delays could fix this but I have not tried yet

A Macintosh terminal SSH session
Slug52local:~# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: XX XX XX XX XX XX XX XX XX XX XX XX XX
10: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
20: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
30: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
40: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
50: 50 51 XX XX XX XX XX XX XX XX XX XX XX XX XX XX
60: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX UU
70: XX XX XX XX XX XX XX XX

so - 80 and 81 decimal but these are hex A0 and hex A2 in the PICs!!! (NB both A0 and A1 translate to decimal 80 in Linux i2c)

Note - at times and for no obvious reason I see "UU" instead of 50 or 51 and the program stops - I need to reboot the Slug and THEN plug in and switch on the i2c devices - can anyone say why?
The slug i2c line runs at 30000 i2c clock pulses per sec. When this happens a Sweex router running i2cdetect can see the i2c PIC devices OK (50000 clock pulses per sec) so the problem seems to be in the Slug. Please
email me


If you start a program running in a ssh session you would stop the program if you closed the console window - The answer is to run "screen"
install with -> apt-get install screen
type -
screen
return
ls or any action
Type Control-a followed by -
_____c new screen
_____p go to previous
_____n go to next
_____S split the screen
_____Tab then n or p in the empty window
_____X remove current section of split window


THIS IS THE CLEVER BIT
_____d detach - (that program will run even if ssh terminal is closed down)
_____later do - screen -r to re attach and see the running program

to clean up -> kill -9 `pidof SCREEN`

see http://aperiodic.net/screen/quick_reference
and http://www.linuxforums.org/applications/the_screen_program.html

These project notes are mainly for my backup - but if you find them of use please email me