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 called
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 |
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" to clean up -> kill -9 `pidof SCREEN` see http://aperiodic.net/screen/quick_reference |
These project notes are mainly for my backup - but if you find them of use please email me