'*** The Garden Monitor 08M *** '*** PicAxe 08M *** '*** Memory $50 (80) to $7F (127) '*** Pin | Function | Gardem_Mon '*** ----+-----------------------------+---------------------------- '*** 1 | +5V | Vcc '*** 2 | SerialIn (Programming) | SerialIn (Programming) '*** 3 | In4, Out4, ADC4 | LED for SelfTest, Addressed Indicator, and Soil Moisture Measurement '*** 4 | In3, InfraIn | SerialIn (be SURE to use Diode to Protect!) '*** 5 | In2, Out2, ADC2, PWM2, Tune | Sensor 2 '*** 6 | In1, Out1, ADC1 | Sensor 1 '*** 7 | Out0, SerialOut, InfraOut | SerialOut '*** 8 | 0V (Ground Return) | 0V (Ground Return) '*** Byte to Word Relationship *** '*** w0 = b1 : b0 '*** w1 = b3 : b2 '*** w2 = b5 : b4 '*** w3 = b7 : b6 '*** w4 = b9 : b8 '*** w5 = b11 : b10 '*** w6 = b13 : b12 '*** W0 (b1:b0) Break down *** '*** b0 = bit7: bit6: bit5: bit4: bit3: bit2: bit1: bit0 '*** b1 = bit15: bit14: bit13: bit12: bit11: bit10: bit9: bit8 '****************************************************************************** '****************************************************************************** '****************************************************************************** '*** Protocal '*** "[aaaaa]f;data1;data2;data3;" '*** Where... '*** "[" and "]" are Required '*** "aaaaa" are this Unit's Address (MUST be 5 digits, including any preceeding Zeros) '*** "f" is Function: 0 to 65535 '*** "dataX" is Data Elements 1, 2, and 3 : ALL are Required 0 to 65535 '*** ";" is a seperator character (can be other non-numeric, but semi-colon is preferred) '*** '*** Address [00000] is Reserved for Master. '*** Function/Data 0; 0; 0; 0 is Reserved, Returns Chip(PicAxe 08M) & Version(v1.0) ("08mv10"). '*** '*** For this implementation '*** Note: All Channels are 1, 2, or 4 '*** Function | Data1 | Data2 | Data3 | Description '*** ---------+--------+--------+--------+------------------------------- '*** Low 0 | Channel| x | x | Makes Channel Low '*** High 1 | Channel| x | x | Makes Channel High '*** Pins 2 | x | x | x | Returns Value of "pins" (Input Levels) '*** ADC10 3 | Channel| x | x | Makes Channel Input and Returns ADC10 (0 - 1023) '*** Count 4 | Channel| Period| x | Measures Pulses on Channel for Period of mS (0 - 65535) '(Built-in Functions come should First: count, play, pulsein, pulseout, pwmout, servo) '*** 9 | Channel| x | x | Returns Value of DS18B20 on Channel (1, 2, 4) '*** 10 | Channel| x | x | Returns Serial Number of DS18B20 on Channel (1, 2, 4) '****************************************************************************** '****************************************************************************** '****************************************************************************** #picaxe 08M #freq m4 #simspeed 10 symbol ADDRESS_HEADER = "[" '*** My Address *** symbol MY_ADDRESS_4 = "4" '*** My Address *** symbol MY_ADDRESS_3 = "3" '*** My Address *** symbol MY_ADDRESS_2 = "2" '*** My Address *** symbol MY_ADDRESS_1 = "1" '*** My Address *** symbol MY_ADDRESS_0 = "0" '*** My Address *** symbol ADDRESS_TRAILER = "]" '*** My Address *** symbol MY_ADDRESS_MSD = "0" '*** My Address *** symbol MY_ADDRESS_LSD = "0" '*** My Address *** symbol MY_ADDRESS = "7" '*** My Address *** symbol RS232_ADD = 0x40 '*** Address Marker ("@") *** symbol RS232_CR = 0x0D '*** Line Feed *** symbol RS232_LF = 0x0A '*** Carrage Return *** symbol RS232_BAUD_MODE = N300 symbol RS232_OUT_LED_PIN = 0x00 symbol IO_1_PIN = 0x01 symbol IO_2_PIN = 0x02 symbol IO_3_PIN = 0x04 symbol RS232_IN_PIN = 0x03 symbol ADC_READ_CYCLES = 0x3F '****************************************************************************** '****************************************************************************** '****************************************************************************** Initialize: '*** Indicate Powered On (3 Quick LED Flashes) *** ' for b0 = 0 to 3 ' low RS232_OUT_LED_PIN ' pause 200 ' high RS232_OUT_LED_PIN ' pause 200 ' next b0 '****************************************************************************** Main: do high RS232_OUT_LED_PIN 'serin RS232_IN_PIN, RS232_BAUD_MODE, (RS232_ADD, MY_ADDRESS_MSD, MY_ADDRESS_LSD), b1, b0 serin RS232_IN_PIN, RS232_BAUD_MODE, (ADDRESS_HEADER, MY_ADDRESS_4, MY_ADDRESS_3, MY_ADDRESS_2, MY_ADDRESS_1, MY_ADDRESS_0, ADDRESS_TRAILER), #w6, #w5, #w4, #w3 '*** Indicate I have been Addressed *** low RS232_OUT_LED_PIN pause 100 '*** Send "@" + MyAddress + Requested Function + Requested Data *** 'serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (RS232_ADD, MY_ADDRESS, b1, b0) serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (ADDRESS_HEADER, MY_ADDRESS_4, MY_ADDRESS_3, MY_ADDRESS_2, MY_ADDRESS_1, MY_ADDRESS_0, ADDRESS_TRAILER, #w6, ";", #w5, ";", #w4, ";", #w3, ";") select case w6 '********************************************************************************************* case 0 '*** Test for Function = "0" *** if w5 = 0 then '*** Test for Reserved Function=0 Data0=0 (Report Chip & Version) *** serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, ("08Mv10") else '*** Make Channel Low *** low w4 end if '********************************************************************************************* case 1 '*** Function 1, Channel : make Channel High *** high w4 '********************************************************************************************* case 2 '*** Function 2 : Returns the Value of "pins" (high/low status of I/O pins) *** serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (#pins) '********************************************************************************************* case 3 '*** Function 3, Channel : make Channel Input and Return ADC10 *** w2 = 0 for w3 = 0 to ADC_READ_CYCLES readadc10 b0, w4 w2 = w2 + w4 next w3 serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (#w2) '********************************************************************************************* case 4 '*** Function 4, Count Channel, Period : Return Count *** count w5, w4, w3 serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (#w3) '********************************************************************************************* case 9 '*** Function 9, Channel : Returns Value of DS18B20 on Channel readtemp12 w5, w4 serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (#w4) '********************************************************************************************* case 10 '*** Function 9, Channel : Returns Serial Number of DS18B20 on Channel readowsn w5 serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (#b6, ";", #b7, ";", #b8, ";", #b9, ";", #b10, ";", #b11, ";", #b12, ";", #b13) '********************************************************************************************* else '*** ERROR: Unimplemented Function *** serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, ("ERROR") end select serout RS232_OUT_LED_PIN, RS232_BAUD_MODE, (RS232_CR, RS232_LF) '*** I'm Done; Indicate No Longer Addressed *** high RS232_OUT_LED_PIN loop '******************************************************************************