Basically, I have a sensor unit and a display unit.
The sensor unit gets temperature from DS18B20, light from TSL235R, and humidity from HH10D and stores the values for retrieval from the display unit.
The display unit retrieves the values from the sensor unit and displays them on a 16x2 serial OLED.
However, I want the display unit to be able to be controlled by 3 buttons, Up Down and Select. I have the menu system on the display working all fine, its just a matter of making the two PICAXEs communicate WITHOUT disrupting user input into the display unit. i.e. no SERIN or long PAUSEs.
I have successfully connected the two chips via I2C. The 20X2 supports being an I2C slave so I used that as the sensor. However, I cannot read from the 20X2 via I2C if the 20X2 is currently reading one of the sensors. (each sensor takes about 0.8seconds to read). I just get all 255 (I2C error) if I try to read at this time (99% of the time). Only if I add a pause after every read (thats fine btw) can I get data through. Sometimes the display unit trys to read the sensor unit whilst not in this pause timeframe and I get 255s.
There is a way I could solve this, is to use background serial, however, I can never get any data to come through, I have tried half a dozen guides on this forum. When using background serial, the 20M2 becomes the sensor unit and the 20X2 with background serial becomes the display unit and the sensor unit sends values to the display unit whenever it reads the sensors.
The problem is, the scratchpad is always empty...
Anyway, this is the program for the I2C method, which would be most ideal as it is simpler. (only the relevant code is included, no menu system or sensor read subroutines)
Sensor unit (20X2):
Display unit (20M2):
^^^ That loop just checks whether one of the three buttons is pressed, and on release, goes to the respective subroutine, I figured that that would be a good place to download new values from the sensor unit as it loops over and over when the device is idle, which is what I want because the temperature will keep updating.
Here is a youtube of the almost-finished menu system to help you understand what I mean. The device is a mini-weather station type deal with a sensor located somewhere else connected by a cable.
http://www.youtube.com/watch?v=B0t9FZlkkT4
The sensor unit gets temperature from DS18B20, light from TSL235R, and humidity from HH10D and stores the values for retrieval from the display unit.
The display unit retrieves the values from the sensor unit and displays them on a 16x2 serial OLED.
However, I want the display unit to be able to be controlled by 3 buttons, Up Down and Select. I have the menu system on the display working all fine, its just a matter of making the two PICAXEs communicate WITHOUT disrupting user input into the display unit. i.e. no SERIN or long PAUSEs.
I have successfully connected the two chips via I2C. The 20X2 supports being an I2C slave so I used that as the sensor. However, I cannot read from the 20X2 via I2C if the 20X2 is currently reading one of the sensors. (each sensor takes about 0.8seconds to read). I just get all 255 (I2C error) if I try to read at this time (99% of the time). Only if I add a pause after every read (thats fine btw) can I get data through. Sometimes the display unit trys to read the sensor unit whilst not in this pause timeframe and I get 255s.
There is a way I could solve this, is to use background serial, however, I can never get any data to come through, I have tried half a dozen guides on this forum. When using background serial, the 20M2 becomes the sensor unit and the 20X2 with background serial becomes the display unit and the sensor unit sends values to the display unit whenever it reads the sensors.
The problem is, the scratchpad is always empty...
Anyway, this is the program for the I2C method, which would be most ideal as it is simpler. (only the relevant code is included, no menu system or sensor read subroutines)
Sensor unit (20X2):
Code:
setfreq m4
hi2csetup i2cslave, %10100000
start:
gosub getlight
gosub gethumid
gosub gettemp
put 0,Whole,Fract,humidity,lightlvl
goto start
Display unit (20M2):
Code:
hi2csetup i2cmaster,%10100000,i2cfast,i2cbyte
await:
if s1 = 1 or s2 = 1 or s3 = 1 then
if s1 = 1 and s2 = 1 then await
if s3 = 1 then
rc3:
if s3 = 0 then
if current > 3 then
gosub beepsel
endif
gosub sel
goto await
endif
goto rc3
elseif s1 = 1 then
rc1:
if s1 = 0 then
if current > 1 then
gosub beepup
endif
gosub up
goto await
endif
goto rc1
elseif s2 = 1 then
rc2:
if s2 = 0 then
if current < 6 then
gosub beepdown
endif
gosub down
goto await
endif
goto rc2
endif
endif
hi2cin 0,(Whole,Fract,humidity,lightlvl)
gosub update
goto await
Here is a youtube of the almost-finished menu system to help you understand what I mean. The device is a mini-weather station type deal with a sensor located somewhere else connected by a cable.
http://www.youtube.com/watch?v=B0t9FZlkkT4