cravenhaven
Senior Member
I have an 08m2 connected to an ESP-01 and a DS18B20 setup on a breadboard pretty much as per the attached diagram.
The program works to upload the data to the thingspeak website, but I am unable to use the confirmation code "serin........" because the picaxe just doesnt seem to be able to read the incoming data string. I have modified the original code so that I just pause between commands, but I also set up a routine to try and read in the ESP responses but all I get is garbage.
I have set up a scope on the output and input of the picaxe (pins C.3 and C.4) and the data streams look identical as the ESP echoes the incoming commands and data.
I have tried connecting my comms cable directly to the ESP (via inverters) so that I can verify exactly what it is sending out in response to the commands etc (and verify the baud rate) and it all looks perfect.
View attachment 19783
This is some of the output to the terminal on the picaxe editor:
The program works to upload the data to the thingspeak website, but I am unable to use the confirmation code "serin........" because the picaxe just doesnt seem to be able to read the incoming data string. I have modified the original code so that I just pause between commands, but I also set up a routine to try and read in the ESP responses but all I get is garbage.
I have set up a scope on the output and input of the picaxe (pins C.3 and C.4) and the data streams look identical as the ESP echoes the incoming commands and data.
I have tried connecting my comms cable directly to the ESP (via inverters) so that I can verify exactly what it is sending out in response to the commands etc (and verify the baud rate) and it all looks perfect.
View attachment 19783
Code:
'Writing PICAXE BASIC Code
'PICAXE Tutorial
'Experiment: PICAXE 08M2 Wi-Fi Communicator
'12 Dec 2015
'Schematic: PICAXE Wi-Fi Communicator.dch
'Code: PICAXE Wi-Fi Communicator.bas
'Overview: Read temperature from DS18B20 into an 08M2,connect an 08M2 to an ESP-01 for
'Wi-Fi operation, and send temperature to Thingspeak every 60 minutes.
#picaxe 08M2 'Identify the PICAXE being used as an 08M2.
#no_data 'Prevent data from being downloaded to PICAXE.
#terminal 9600 'Call terminal and set baud rate to 4800.
setfreq m8
symbol temp=C.1 'DS18B20 should is connected to Pin C.1.
symbol CH_PD=C.2 'CH_PD pin on ESP-01 is connected to Pin C.2.
symbol baud=T9600_8 'Set baud rate for serout transmissions.
symbol temp_now = b4 'Symbol and storage location for temperature reading from DS18B20.
GOSUB initesp
main:
check_temp:
readtemp C.1, temp_now 'Read temperature from DS18B20, and store it in temp_now.
bintoascii temp_now,b5,b6,b7 'Convert current temperature from binary to ASCII and
'store it in b5,b6,b7.
ESP_On:
high CH_PD 'Enables ESP-01 module.
pause 1000 'Pause 1 second to allow ESP-01 to boot.
CIPSTART:
serout C.4,baud,("AT+CIPSTART=",34,"TCP",34,",",34,"184.106.153.149",34,",80",13,10)
'Send command string to ESP-01+CR+LF to access Thingspeak.
;serin[3000,send_fail],C.3,baud,("OK") 'Wait up to 3 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
GOSUB receivedata
sertxd("CIPSTART OK",13,10)
PAUSE 3000
CIPSEND:
serout C.4,baud,("AT+CIPSEND=45",13,10)
'Send AT+CIPSEND command+byte total+CR+LF to ESP-01 to advise Thingspeak to expect
'45 bytes of data. Note that the number of bytes advised must agree with the number
'of bytes sent in the next serout command. The quotation marks and the commas don't
'count, but everything else does. Count the bytes in the following serout command to
'see that they do total 45. Each time you change the length of the data sent, you
'must change the total in the AT+CIPSEND command string to agree.
;serin[3000,send_fail],C.3,baud,("OK") 'Wait up to 3 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
GOSUB receivedata
sertxd("CIPSEND OK",13,10)
PAUSE 3000
send_data:
sertxd(b5,b6,b7,13,10)
serout C.4,baud,("GET /update?key=ABCDEFGHIJKLMNOP&field1=",b5,b6,b7,13,10)
'Send write key+temperature+CR+LF to Thingspeak. Note that this transmission
'includes data for only Field 1. Add an additional field and data by adding &field2
'plus the data for as many fields as are available. Change the AT+CIPSEND command
'string to agree with the new byte total.
;serin[3000,send_fail],C.3,baud,("OK") 'Wait up to 3 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
GOSUB receivedata
sertxd("DATASEND OK",13,10)
PAUSE 3000
;serin[3000],C.3,baud,("CLOSED") 'Wait up to 3 seconds to receive CLOSED. If CLOSED is
'not received, go to send_fail; otherwise proceed.
;sertxd("CLOSED",13,10)
;PAUSE 3000
;CWQAP2:
;serout C.4,baud,("AT+CWQAP",13,10) 'Send disconnect from Wi-Fi command+CR+LF to ESP-01.
;serin[3000,send_fail],C.3,baud,("OK") 'Wait up to 3 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
;sertxd("QAP OK",13,10)
;PAUSE 3000
ESP_Off:
;pause 1000 'Pause 1 second to allow ESP-01 to complete operations.
;low CH_PD 'Disables ESP-01 module.
hold:
for w7 = 1 to 8'96 'Establish a for/next loop for 896 repetitions.
pause 4000 'Pause 4 seconds.
next w7 'Next loop: 3585 seconds + 15 seconds for program execution = 60 minutes.
goto main
send_fail:
sertxd("SEND FAILED",13,10)
;goto CWQAP2
initesp:
AT:
serout C.4,baud,("AT",13,10) 'Send attention command+CR+LF to ESP-01.
;serin[3000,send_fail],C.3,baud,("OK") 'Wait up to 3 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
GOSUB receivedata
sertxd("AT OK",13,10)
PAUSE 3000
CWQAP:
serout C.4,baud,("AT+CWQAP",13,10) 'Send disconnect from Wi-Fi command+CR+LF to ESP-01.
;serin[3000,send_fail],C.3,baud,("OK") 'Wait up to 3 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
GOSUB receivedata
sertxd("QAP OK",13,10)
PAUSE 3000
CWMODE:
serout C.4,baud,("AT+CWMODE=1",13,10) 'Send STA command+CR+LF to ESP-01.
;serin[3000,send_fail],C.3,baud,("OK") 'Wait up to 3 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
GOSUB receivedata
sertxd("CWMODE OK",13,10)
PAUSE 3000
'The "34" codes in the lines following send commas to separate the data for the ESP-01.
CWJAP:
serout C.4,baud,("AT+CWJAP=",34,"XXXXXXXXX",34,",",34,"YYYYYYYYY",34,13,10)
'Send command string to join LAN+SSID+LAN password+CR+LF to ESP-01.
;serin[6000,send_fail],C.3,baud,("OK") 'Wait up to 6 seconds to receive OK. If OK is
'not received, go to send_fail; otherwise proceed.
GOSUB receivedata
sertxd("JAP OK",13,10)
PAUSE 3000
return
receivedata:
for b0 = 0 to 30 ;start a loop
serin [300],C.3,baud,b1 ; receive serial value
write b0,b1 ; write value into b1
next b0 ; next loop
for b0 = 0 to 30 ;start a loop
read b0,b1 ; read value into b1
sertxd (b1," ") ; send serial value
next b0 ; next loop
for b0 = 0 to 30 ;start a loop
read b0,b1 ; read value into b1
sertxd (#b1," ") ; send serial value
next b0 ; next loop
return
Code:
018
!
[14] [F8]
[14] j
[A1] k k k k k k k k k 33 13 20 248 13 20 106 10 10 10 10 10 10 10 10 10 10 10 10 10 13 161 107 107 107 107 107 107 107 107 107 DATASEND OK
[E1] [E1]
! [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] 225 225 13 33 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 CIPSTART OK
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 CIPSEND OK
017
!
[14] [F8]
[14] S H H
[A1] k k k k k k k k k k k k k k k k k k k k 33 13 20 248 13 20 83 72 72 13 161 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 DATASEND OK
[E1] [E1]
! [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] 225 225 13 33 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 CIPSTART OK
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 CIPSEND OK
017
!
[14] [F8]
[14] j
[A1] k k k k k k k k k k k k k k k k k k k k 33 13 20 248 13 20 106 10 10 13 161 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 DATASEND OK
[E1] [E1]
! [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] [16] 225 225 13 33 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 CIPSTART OK
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 CIPSEND OK
017
!
[14] [F8]
[14] j
[A1] k k k k k k k k k k k k k k k k k k 33 13 20 248 13 20 106 10 10 10 10 13 161 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 107 DATASEND OK