picxaxe 08m2 and ESP8266 comms errors

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
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
This is some of the output to the terminal on the picaxe editor:
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
 

hippy

Technical Support
Staff member
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.
It may be that the data from the ESP8266 comes back too soon and too quickly for the 08M2 to handle correctly. Especially in the way you are receiving a byte at a time and writing it to Eeprom.

You could try running the 08M2 faster but using background receive buffering would be the best way to receive variable length data. Unfortunately that is only available on X2 devices. You could however grab the first couple of bytes using HSERIN on an M2.
 

cravenhaven

Senior Member
That's a slightly different twist on the article I followed in the first place. The one I followed had the command followed by a detection of an OK response, but I cant seem to read anything in so the test fails. The article you link to Tracecom is the same setup but with pause timeouts between commands, which is what I did to get it working. However the problem still exists in that I want to be able to read data in via the ESP, so that is the solution I'm chasing.
 

tracecom

Senior Member
I see that you have changed the data rates in the code from the article you first followed. Have you tried the code with the data rates set as they were defined in the article?
 
Last edited:

PhilHornby

Senior Member
Modify the ESP8266 code, not the Picaxe...

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.
The ESP8266 is much more than a simple Wifi-Serial adapter- it's a fully-fledged Wifi-enabled microcontroller. It just happens to be normally supplied with the so-called "AT" firmware loaded.

You can solve your problem, by modifying the code that the ESP8266 is running.

This can be done at several different levels: the most difficult, would be to move your entire application to the ESP8266 (libraries exist to interface with the DS18B20, but the ESP8266-01 module might be a little short of connections to the outside world to do this easily).

The easiest, would be to implement your own "Wifi-to-serial" interface and retain the Picaxe. The ESP8266 code doesn't need to do much: connect to a known Wifi access point, pass all received serial data to known web server, and pass all received IP data back to serial - after a short delay. (This short delay is probably all that is required to get your project working)

Last time I looked at ESP8266 Basic , I decided it wasn't quite ready for the 'big time', but I'm sure it could do this job. NODELUA would also be worth investigating. Using the Arduino IDE with the ESP8266 represents a much larger learning curve; HERE would be as good a place to start as any.
 

Janne

Senior Member
I have to admit I've not tried any other ESP8266 FW's except for nodeMCU.. but I can highly recommend that. Like nodeLUA, it's based on LUA language. The language is interpreted, like picaxe basic. This means that there is obviously no need to compile the whole firmware when making changes to the code, just upload the changed bits.
The best part of the thing is the REPL (Read-Eval-Print Loop) console that is the default function of the uart. What this allows is to insert commands or code to execute directly from the uart, so it's the perfect tool to try out stuff.
Other features worth mention include a crude but usable filesystem to store data or program files in the inbuilt flash.
The official builds for some reason are dated, and the network stack on them seems highly unstable (usually they even hang after a couple of refreshes of the hello world server). Developer brach builds seem to work pretty much perfectly, at least the ones I've tried.

http://nodemcu.com
https://github.com/nodemcu/nodemcu-firmware


As to the OP problem, It could be possible to fix it by simply reducing the baudrate.
 

tracecom

Senior Member
Using LUA to program the ESP8266 is certainly doable. However, the PICAXE works very well communicating with the ESP using the AT command set. I have built the circuit and used the code in the first article the OP mentioned, and I am sure that it works just as described.
 

Goeytex

Senior Member
The 08M2 will struggle and fail when trying to to receive multiple back-to-back data bytes with SERIN at 9600_8. There is simply not enough time between bytes for a Picaxe to receive a byte, process it, and then get ready to receive the next byte.

When using SERIN at 9600 baud, and more than 1 or 1 or 2 bytes are to be received, the Picaxe should be running at either 16 or 32 MHz and SERIN should be set to either 9600_16 or 9600_32. (32MHz will give the best performance)
 

cravenhaven

Senior Member
Thanks for all the suggestions and sorry for the delayed response.
Today I tried both changing my serial input routine and various picaxe speeds and baud rates and still I get either nothing or rubbish responses.
I tried:
chip speed up to 32MHz
set ESP baud rate to 4800, then down to 1200
tried both 'N' and 'T' polarities
used serin [3000],C.3,baud,b0,b1,b2 after each command instead of a subroutine and loop

I will try sending the ESP response straight to a terminal session to try and understand what is going on.
 

Hemi345

Senior Member
cravenhaven:298717 said:
I will try sending the ESP response straight to a terminal session to try and understand what is going on.
Thats what I do when working with the ESP to PICAXE comms. I have a CP2102 usb to serial adapter connected to the ESP and also the programming lead on the PIC and watch two terminal windows to see whats being sent and received. The new black ESP-01 1Mb has changed alot compared to the blue ones. Can't expect even two ESP modules ordered at the same time to have the same firmware, but easy enough to update them once you figure that out and have a programming board built to do it. I'm just using the AT firmware.
 

cravenhaven

Senior Member
Well, after much messing around including building myself a proper TTL serial interface, I discovered that I cant set the baud rate on the ESP to anything less than the default 9600. The only baud rate command it seems to accept is the AT+CIOBAUD=xxxxx, I also tried AT+UART(DEF/CUR)= and AT+IPR. Strangely enough the AT+IPR had the effect of setting to an unknown baud rate when I sent it via the picaxe program, but just error-ed out when typed in directly.
I ran the 08M2 at 32MHz and monitored the response of the ESP via a separate serial link, but the PICAXE just wouldnt receive anything even when setting the serin timeout to 10 seconds. The serial monitor showed that the ESP was responding correctly.

I would like to update the firmware, but there seems to be a mass of confusion on the www about versions and methods and added to by Expressif requiring the latest firmware to only support the later model chips with larger flash and I dont know what flash size my boards are.
Tomorrow I'm going to try another input port. just in case there is some problem with C.3, I had noticed on the picaxe website that it mentioned a requirement to have a diode externally connected between pin C.3 and Vcc on the 08m2 so maybe this is having an effect?.
 

Goeytex

Senior Member
I ran the 08M2 at 32MHz and monitored the response of the ESP via a separate serial link, but the PICAXE just wouldnt receive anything even when setting the serin timeout to 10 seconds. The serial monitor showed that the ESP was responding correctly.
I do not know anything about the ESP but I do know how to get serial coms working with a Picaxe. It is highly unlikely that there is anything wrong with PINC.3. But it may be worth testing if all else fails.

Below is a somewhat crude program I slapped together to test the serial com link between the ESP and the Picaxe. There is one assumption .. That the ESP is operating at 9600 baud. You can add more "TEST" subs that set different baud rates & polarities until you get a combination that shows success. The fact that the ESP responds to serout at T9600_32 should be proof enough that the ESP is operating at 9600. Run the program and see what happens. IF you get a success, then you know that the baud rate is correct and that serin is working as expected.

Note: Back in beta, I had trouble with the PE6 terminal responding correctly at 38400 and above. You may want to use a different terminal program just in case. Putty is good as well as Br@ys V1.9 . Just make sure that the terminal baud rate is set to 38400 as this is the baud of "SERTXD" when the Picaxe is set to 32MHz

Code:
[color=Navy]#picaxe [/color][color=Black]08M2    [/color][color=Green]'// Identify the PICAXE being used as an 08M2.[/color]
[color=Navy]#no_data        [/color][color=Green]'// Prevent data from being downloaded to PICAXE.[/color]
[color=Navy]#terminal 38400 [/color][color=Green]'// Call terminal and set baud rate to 38400.[/color]
[color=Blue]setfreq M32     [/color][color=Green]'// Termial must be 38400 for Sertxd to communicate[/color]
[color=Blue]Pause [/color][color=Navy]8000      [/color][color=Green]'// allow terminal time to open [/color]

[color=Blue]Symbol CH_PD [/color][color=DarkCyan]= [/color][color=Blue]C.2  [/color][color=Green]'CH_PD pin on ESP-01 is connected to Pin C.2.[/color]
[color=Blue]Symbol Baud [/color][color=DarkCyan]= [/color][color=Blue]T9600_32
Symbol [/color][color=Purple]Test [/color][color=DarkCyan]= [/color][color=Purple]b10[/color]
[color=Blue]Sertxd ([/color][color=Red]"Testing SERIN / ESP Response"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf) [/color]

[color=Black]ESP_On:[/color]
[color=Blue]high CH_PD [/color][color=Green]'Enables ESP-01 module.[/color]
[color=Blue]pause [/color][color=Navy]4000 [/color][color=Green]'Pause 1 second to allow ESP-01 to boot.[/color]
[color=Blue]Sertxd ([/color][color=Red]"ESP Powered up"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)[/color]

[color=Black]Main:

   [/color][color=Blue]DO
  
      Gosub [/color][color=Black]Test1
      [/color][color=Blue]Gosub [/color][color=Black]Test2
  
   [/color][color=Blue]Loop [/color]

[color=Black]Test1:   [/color][color=Green]'//AT Test
  [/color][color=Purple]Test [/color][color=DarkCyan]= [/color][color=Navy]1
  [/color][color=Blue]serout C.4[/color][color=Black],[/color][color=Blue]baud[/color][color=Black],[/color][color=Blue]([/color][color=Red]"AT"[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue]) [/color][color=Green]'Send attention command+CR+LF to ESP-01.
  [/color][color=Blue][PLAIN]serin[[/PLAIN][/color][color=Navy]8000[/color][color=Black],NO_ACK[/color][color=Blue][PLAIN]][/PLAIN][/color][color=Black],[/color][color=Blue]C.3[/color][color=Black],[/color][color=Blue]baud[/color][color=Black],[/color][color=Blue]([/color][color=Red]"OK"[/color][color=Blue]) [/color][color=Green]'Wait up to 2 seconds to receive OK
  [/color][color=Blue]Goto [/color][color=Black]ACK
  [/color][color=Blue]return
 [/color]
[color=Black]Test2:  [/color][color=DarkCyan]// [/color][color=Black]CIP [/color][color=Purple]Test
  Test [/color][color=DarkCyan]= [/color][color=Navy]2
   [/color][color=Green]'Send CIP .
  [/color][color=Blue]serout C.4[/color][color=Black],[/color][color=Blue]baud[/color][color=Black],[/color][color=Blue]([/color][color=Red]"AT+CIPSTART="[/color][color=Black],[/color][color=Navy]34[/color][color=Black],[/color][color=Red]"TCP"[/color][color=Black],[/color][color=Navy]34[/color][color=Black],[/color][color=Red]","[/color][color=Black],[/color][color=Navy]34[/color][color=Black],[/color][color=Red]"184.106.153.149"[/color][color=Black],[/color][color=Navy]34[/color][color=Black],[/color][color=Red]",80"[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue])
  [PLAIN]serin[[/PLAIN][/color][color=Navy]8000[/color][color=Black],NO_ACK[/color][color=Blue][PLAIN]][/PLAIN][/color][color=Black],[/color][color=Blue]C.3[/color][color=Black],[/color][color=Blue]baud[/color][color=Black],[/color][color=Blue]([/color][color=Red]"OK"[/color][color=Blue]) [/color][color=Green]'Wait up to 2 seconds to receive OK
  [/color][color=Blue]Goto [/color][color=Black]ACK 
  [/color][color=Blue]return
 

  [/color][color=Black]NO_ACK:
  [/color][color=Blue]Sertxd ([/color][color=Red]"Test "[/color][color=Black],#[/color][color=Purple]Test[/color][color=Black],[/color][color=Red]" Fail: Serin did not receive OK"[/color][color=Black], [/color][color=Blue]CR[/color][color=Black],[/color][color=Blue]LF)
  Goto [/color][color=Black]End_test
  [/color][color=Blue]Return

  [/color][color=Black]ACK:
  [/color][color=Blue]Sertxd ([/color][color=Red]"Test "[/color][color=Black],#[/color][color=Purple]Test[/color][color=Black], [/color][color=Red]" Success: Serin received OK"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
  
  [/color][color=Black]End_Test:
  [/color][color=Blue]Return[/color]
Goey
 

PhilHornby

Senior Member
I suspect they started life as Gosubs, but got changed to Gotos. (At which point the Returns following the Gotos should have been removed.) They do work as shown though.
 

hippy

Technical Support
Staff member
Tomorrow I'm going to try another input port. just in case there is some problem with C.3, I had noticed on the picaxe website that it mentioned a requirement to have a diode externally connected between pin C.3 and Vcc on the 08m2 so maybe this is having an effect?.
The diode is required on 08M2 C.3 only when the input voltage applied to C.3 may be higher than the PICAXE supply voltage. If the ESP8266 runs on the same voltage as the 08M2 the diode is not needed, though it does no harm to add it anyway ( noting cathode / pointy-end goes towards V+ ).

One trick if C.3 is being used without a diode and used with a higher voltage than PICAXE supply is to connect C.3 to any other spare or unused digital always-input pin which does have an internal clamping diode. That can help if a PCB or breadboard layout has been created and simply moving the signal is not desired. Serial can then of course be read from either pin. Take care to keep the second pin as a digital input.
 

Goeytex

Senior Member
Goey - shouldn't all your Goto commands be Gosubs instead?
No. It is an intentional un-elegant, sloppy "trick" to allow skipping over a section of code. Each return assures an exit from the sub and a jump back to the main loop. I can see Dijkstra rolling his eyes.
 

cravenhaven

Senior Member
Hmmm!!! unusual results.
I tried your test code Goey, and for some reason it actually worked even though it was identical (except for a label name) to what I was already doing. I even tried changing my label to the same as yours, which of course made no difference :rolleyes:.

At this stage I had my 'new' TTL serial cable connected to the ESP in parallel with the picaxe and so could monitor and command (using putty) the esp simultaneously to the program. I had also changed my program to keep retrying a command (trying varying delays) unless the serin succeeded. While the program was running (and getting nowhere) I attempted to change the echo status of the ESP by interjecting a 'ATEO' command and noticed that suddenly the next command was being tried ie serin had succeeded ;). So after some experimenting I discovered that interjecting a <ctrl>J, ie LF, while the serin timeout was in progress had the effect of causing serin to succeed :confused:.
Leading on from this discovery I added an extra 'LF' to the end of each serout command which resulted in the subsequent serin command succeeding reliably.
eg
serout C.4,baud,("AT",13,10,10)
serin[8000,NO_ACK],C.3,baud,("OK")


Anyone care to comment on why this would work?.
 

cravenhaven

Senior Member
I spent days trying to update the firmware in my ESP-01 chips; this is what finally worked. http://www.allaboutcircuits.com/projects/update-the-firmware-in-your-esp8266-wi-fi-module/ The slightest deviation from the instructions disrupts the process.
Thanks tracecom. I intend to try this out but as I mentioned above, which firmware does one use. I noticed that the firmware referenced in the article is quite old now and the additional download called AT_V0.50 is not listed with the later firmwares. Also the downloads seem to be the source files and need compiling to be usable?. How does one get the actual compiled file?.
 

Goeytex

Senior Member
serout C.4,baud,("AT",13,10,10)
serin[8000,NO_ACK],C.3,baud,("OK")

Anyone care to comment on why this would work?.
I can only guess.

IF ..... the ESP begins its response after the first 10 is sent, then the second 10 adds a 1 ms delay (+ processing overhead) before serin is active.

To test this theory ....
Code:
serout C.4,baud,("AT",13,10)
pause 4 
serin[8000,NO_ACK],C.3,baud,("OK")
You could also try pacing serout by adding some time between bytes sent to see if the ESP responds differently

Code:
serout C.4,baud,("A") : pause 4
serout C.4,baud,("T") : Pause 4
serout C.4,baud,(13) : pause 4
serout C.4,baud,(10) : Pause 4

serin[8000,NO_ACK],C.3,baud,("OK")
Does the above work ? Consistently ?

If you have a scope or a logic analyzer you could measure the time it takes from when 13/10 is sent to when ESP sends back the first response byte. Might be good information to have.
 

tracecom

Senior Member
Thanks tracecom. I intend to try this out but as I mentioned above, which firmware does one use. I noticed that the firmware referenced in the article is quite old now and the additional download called AT_V0.50 is not listed with the later firmwares. Also the downloads seem to be the source files and need compiling to be usable?. How does one get the actual compiled file?.
This firmware works even though it has been superseded. http://bbs.espressif.com/download/file.php?id=1079

The firmware unzips into separate files, which have to be added to the programmer software just as described in the article. Step by step is tedious, but I have found no other reliable way, and after I upgraded a few ESP-01s, it became routine.
 

joeygbsn

New Member
When I was trying to use the AT firmwares I was able to find some AT binaries which seemed to have been pre compiled. I'll post a link to a Google Drive at the bottom of this post which has some for download. There is also a flasher. With these you don't have to do the memory mapping and stuff like with the flasher provided by espressif. Just point the flasher to the binary and select the right com port and hit flash. This works alright, but as soon as I found esp8266basic I haven't used anything else.
https://drive.google.com/folderview?id=0BxdLxDCD6HidN2g3US1kVWVqQ3M&usp=sharing
 

Janne

Senior Member
For firmware updates I'd recommend the ESPTOOL. It requires python, but who wouldn't have that already these days :) https://github.com/themadinventor/esptool
Updating the firmware is easy; for example starting an FW update with the default 9600 baudrate and serial port /dev/ttyUSB3 would go like this(ofc replace the .bin file with your FW file):
Code:
python esptool.py --port /dev/ttyUSB3 write_flash 0x00000 nodemcu-dev-7-modules-2016-02-21-08-51-45-float.bin
 

cravenhaven

Senior Member
If you have a scope or a logic analyzer you could measure the time it takes from when 13/10 is sent to when ESP sends back the first response byte. Might be good information to have.
I monitored the timing on the scope today after rebuilding my level converters as per my post on a one FET level shifter http://www.picaxeforum.co.uk/showthread.php?28980-One-transistor-noninverting-bidirectional-level-shifter and noted that the ESP begins responding approx 1ms after the first bit is received.
I'll have to have another look tomorrow with auto echo turned off and see how long it takes for the OK to be sent.
 

cravenhaven

Senior Member
I monitored the timing on the scope today after rebuilding my level converters as per my post on a one FET level shifter http://www.picaxeforum.co.uk/showthread.php?28980-One-transistor-noninverting-bidirectional-level-shifter and noted that the ESP begins responding approx 1ms after the first bit is received.
I'll have to have another look tomorrow with auto echo turned off and see how long it takes for the OK to be sent.
Looks like it takes between about 60 and 130 us for the ESP to start responding after receiving a command.
 

cravenhaven

Senior Member
I decided to connect a separate 08m2 to just monitor the serial output of the ESP and then send the output to the serial link. I wanted to confirm that the data was not being distorted by my setup and that it could be possible to actually receive data from the ESP into a picaxe.
Code:
[color=Navy]#picaxe [/color][color=Black]08M2 [/color][color=Green]'Identify the PICAXE being used as an 08M2.[/color]
[color=Navy]#no_data [/color][color=Green]'Prevent data from being downloaded to PICAXE.[/color]
[color=Navy]#terminal 38400 [/color][color=Green]'Call terminal and set baud rate to 38400.[/color]
[color=Blue]setfreq m32
symbol [/color][color=Black]index1[/color][color=DarkCyan]=[/color][color=Purple]b27[/color]
[color=Blue]symbol [/color][color=Black]baud[/color][color=DarkCyan]=[/color][color=Blue]T9600_32[/color]

[color=Black]main:
      [/color][color=Blue]DO
            [PLAIN]SERIN[[/PLAIN][/color][color=Navy]40000[/color][color=Blue][PLAIN]][/PLAIN][/color][color=Black],[/color][color=Blue]C.3[/color][color=Black],baud,[/color][color=Blue](lf)[/color][color=Black],[/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black],[/color][color=Purple]b8[/color][color=Black],[/color][color=Purple]b9[/color][color=Black],[/color][color=Purple]b10[/color][color=Black],[/color][color=Purple]b11[/color][color=Black],[/color][color=Purple]b12[/color][color=Black],[/color][color=Purple]b13[/color][color=Black],[/color][color=Purple]b14[/color][color=Black],[/color][color=Purple]b15[/color][color=Black],[/color][color=Purple]b16
            [/color][color=Blue]SERTXD([/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black],[/color][color=Purple]b8[/color][color=Black],[/color][color=Purple]b9[/color][color=Black],[/color][color=Purple]b10[/color][color=Black],[/color][color=Purple]b11[/color][color=Black],[/color][color=Purple]b12[/color][color=Black],[/color][color=Purple]b13[/color][color=Black],[/color][color=Purple]b14[/color][color=Black],[/color][color=Purple]b15[/color][color=Black],[/color][color=Purple]b16[/color][color=Blue])
      LOOP[/color]
It received and displayed the data exactly as it should have although even with the small loop it could not keep up with the data rate so missed bits of it.

I'll now go ahead with a firmware update to the ESP so that I can reduce the baud rate to an acceptable level for the picaxe.
Thanks everyone for their help in understanding how this all works.
 

Goeytex

Senior Member
Serin @ 4800_32 should allow all the bytes to be received without error as the time between byte will be greater, giving the picaxe more time to process each byte and then move to the next.

This is where background receive on Picaxe X2 chips performs realy well. Baud rate is not an issue since all the Picaxe firmware has to do is move the data from the USART buffer into the scratchpad (done in the background while other code is running). A flag is raised when data is received into the scratchpad. You can even use the hserptr system variable to see how many bytes have been received. A much better and more reliable solution IMO, but the trade offs are the additional cost and size of the X2 Chips.
 
Top