ESP8266 BASIC

lbenson

Senior Member
I made some slight changes; j5.html on the PC invoking j5a.js:
Code:
<html><head><link type=text/css rel=stylesheet href=http://192.168.1.144:20780/s.css>
</head><body></body>
<script>var arrayCurVals = [1,1,0,123,"W"];</script>
<script src=http://192.168.1.144:20780/b5a.js></script>
</html>
j5a.js on the pi:
Code:
document.body.innerHTML = "" +
'<html><head><title> LED Control</title></head>' +
'<body><form name = input method = get>' +
' <font color=blue><font size=5>Picaxe Web Server</font><br><br>' +
'  <font color=black>' +
'  <table border="1">' +
'  <tr><td><input type="radio" id="A" name="L" value="1">LED ON</td>' +
'  <td><input type="radio" id="B1" name="L" value="0">LED OFF</td></tr>' +
'  <tr><td><input type="radio" id="C" name="P" value="1">PWM ON </td>' +
'  <td><input type="radio" id="D" name="P" value="0">PWM OFF</td></tr>' +
'  <tr><td><input type="radio" id="E" name="R" value="1">Ramp/Fade ON  </td>' +
'  <td><input type="radio" id="F" name="R" value="0">Ramp/Fade ' +
'    OFF</td></tr></table>' +
'' +
'  <p>PWM Duty Cycle:</p>' +
'  <input type="text" id="G" name="N"><br><br>' +
'' +
'  <p>Select LED:</p>' +
'  <input type="radio" id="R" name="X" value="R">Red<br>' +
'  <input type="radio" id="Y" name="X" value="Y">Yellow<br>' +
'  <input type="radio" id="B" name="X" value="B">Blue<br>' +
'  <input type="radio" id="G" name="X" value="G">Green<br>' +
'  <input type="radio" id="W" name="X" value="W">White<br>' +
'  <input type="radio" id="O" name="X" value="O">Orange<br>' +
'' +
'  <br><button type=submit>Submit</button>' +
'</form></body></html>        '
var ledStatus = arrayCurVals[0];  // this will be "0"
var pwmStatus = arrayCurVals[1]; //this will be "1"
var pwmRamp = arrayCurVals[2]; //this will be "1"
var pwmDuty = arrayCurVals[3]; //this will be, e.g., "321"
var ledColor = arrayCurVals[4]; // this will be "W"

if (ledStatus == 1) { document.getElementById("A").setAttribute("checked", true); }
else { document.getElementById("B1").setAttribute("checked", true); }
if (pwmStatus == 1) { document.getElementById("C").setAttribute("checked", true); }
else { document.getElementById("D").setAttribute("checked", true); }
if (pwmRamp == 1) { document.getElementById("E").setAttribute("checked", true); }
else { document.getElementById("F").setAttribute("checked", true); }
document.getElementById("G").value=pwmDuty
document.getElementById(ledColor).setAttribute("checked", true);
js5_html3.jpg
Here's a pebble representation of what the picaxe would be connected to (I'm not actually using a breadboard; the red module is a mosfet board for PWMing; ESP connection not shown):
px_js_web scheme.jpg
 

Electronics Learner 123

Well-known member
I made some slight changes; j5.html on the PC invoking j5a.js:
Code:
<html><head><link type=text/css rel=stylesheet href=http://192.168.1.144:20780/s.css>
</head><body></body>
<script>var arrayCurVals = [1,1,0,123,"W"];</script>
<script src=http://192.168.1.144:20780/b5a.js></script>
</html>
j5a.js on the pi:
Code:
document.body.innerHTML = "" +
'<html><head><title> LED Control</title></head>' +
'<body><form name = input method = get>' +
' <font color=blue><font size=5>Picaxe Web Server</font><br><br>' +
'  <font color=black>' +
'  <table border="1">' +
'  <tr><td><input type="radio" id="A" name="L" value="1">LED ON</td>' +
'  <td><input type="radio" id="B1" name="L" value="0">LED OFF</td></tr>' +
'  <tr><td><input type="radio" id="C" name="P" value="1">PWM ON </td>' +
'  <td><input type="radio" id="D" name="P" value="0">PWM OFF</td></tr>' +
'  <tr><td><input type="radio" id="E" name="R" value="1">Ramp/Fade ON  </td>' +
'  <td><input type="radio" id="F" name="R" value="0">Ramp/Fade ' +
'    OFF</td></tr></table>' +
'' +
'  <p>PWM Duty Cycle:</p>' +
'  <input type="text" id="G" name="N"><br><br>' +
'' +
'  <p>Select LED:</p>' +
'  <input type="radio" id="R" name="X" value="R">Red<br>' +
'  <input type="radio" id="Y" name="X" value="Y">Yellow<br>' +
'  <input type="radio" id="B" name="X" value="B">Blue<br>' +
'  <input type="radio" id="G" name="X" value="G">Green<br>' +
'  <input type="radio" id="W" name="X" value="W">White<br>' +
'  <input type="radio" id="O" name="X" value="O">Orange<br>' +
'' +
'  <br><button type=submit>Submit</button>' +
'</form></body></html>        '
var ledStatus = arrayCurVals[0];  // this will be "0"
var pwmStatus = arrayCurVals[1]; //this will be "1"
var pwmRamp = arrayCurVals[2]; //this will be "1"
var pwmDuty = arrayCurVals[3]; //this will be, e.g., "321"
var ledColor = arrayCurVals[4]; // this will be "W"

if (ledStatus == 1) { document.getElementById("A").setAttribute("checked", true); }
else { document.getElementById("B1").setAttribute("checked", true); }
if (pwmStatus == 1) { document.getElementById("C").setAttribute("checked", true); }
else { document.getElementById("D").setAttribute("checked", true); }
if (pwmRamp == 1) { document.getElementById("E").setAttribute("checked", true); }
else { document.getElementById("F").setAttribute("checked", true); }
document.getElementById("G").value=pwmDuty
document.getElementById(ledColor).setAttribute("checked", true);
View attachment 23647
Here's a pebble representation of what the picaxe would be connected to (I'm not actually using a breadboard; the red module is a mosfet board for PWMing; ESP connection not shown):
View attachment 23648
When you get this working please be sure to share the code please? It looks great so far

Once you get the PICAXE and ESP hardware and program it to serve up a page, come back if you still need help figuring out how to act on a response to turn an LED on/off. There is a wealth of information on this forum. Search here for Wiznet as those threads cover a lot of the concepts for serving up a page and acting on data returned in the query string.

I have to say that this is a very ambitious project for your first experience with the PICAXE and ESP. You'll in for a lot of reading.
Which forums do you recommend that I read that are simple, e.g sending a variable from a website to Picaxe or turning an led on/off?
 

lbenson

Senior Member
Which forums do you recommend that I read that are simple, e.g sending a variable from a website to Picaxe or turning an led on/off?
Nothing is simple about this process with a picaxe, because of the complexity of the interaction between the picaxe and the esp (or whatever TCP-to-serial module you have). Have you tried to follow hippy's code in the "Where's the Wizard?" thread? That boils it down pretty well, though it no doubt can be daunting.
 

Electronics Learner 123

Well-known member
Nothing is simple about this process with a picaxe, because of the complexity of the interaction between the picaxe and the esp (or whatever TCP-to-serial module you have). Have you tried to follow hippy's code in the "Where's the Wizard?" thread? That boils it down pretty well, though it no doubt can be daunting.
I have, it is very daunting, If there were some simple code that literally turned an led on/off and sent a variable over WiFi using an esp8266 it would really help.

I also don’t quite understand how to picaxe communicates with the esp.

Electronics Learner 123
 

hippy

Senior Member
If there were some simple code that literally turned an led on/off and sent a variable over WiFi using an esp8266 it would really help.
Unfortunately there isn't. One way is to control an ESP2866 using AT commands, and to hide the code which does that inside include files, macros and other definitions. Another way is to have simpler SERIN and SEROUT commands interface with code programmed within the ESP8266 which handles what it receives from the PICAXE or over the network.. An alternative is to use something other than an ESP8266.

Unfortunately there isn't a pre-written framework for any of that, no 'this is how to do it' defined and documented for all cases where one might want to connect a PICAXE over a network.

I also don’t quite understand how to picaxe communicates with the esp.
In most case 'via serial' because that's the easiest mechanism to use with a PICAXE and ESP8266 or anything else.

As to what is sent and received; that depends on the implementation.
 

Electronics Learner 123

Well-known member
Another way is to have simpler SERIN and SEROUT commands interface with code programmed within the ESP8266 which handles what it receives from the PICAXE or over the network.. An alternative is to use something other than an ESP8266.
How would I do this? Are there any examples, would this mean that the esp receives data and this transmits this to the Picaxe, would the esp8226 be programmed etc...

Thanks in advance
 

lbenson

Senior Member
How would I do this? Are there any examples, would this mean that the esp receives data and this transmits this to the Picaxe, would the esp8226 be programmed etc...
I'm not sure that asking the same question in a different way (or with a different thread) is going to get you a different answer.

If you hook up an ESP's Rx and Tx to a usb/serial module as suggested above, plug the usb module into your pc, start a terminal program at 115200 baud, and type AT<Enter><Ctrl-J>, you should get back "OK".

That is exactly the same thing that happens if you send "AT",cr,lf to the ESP with the picaxe, and the picaxe will get back exactly the same thing, which you then have to deal with. This is why I've suggested that you have a play on your PC with that setup--you will see the kind of commands that you send (e.g., to connect to your wifi), and the kind of responses you get back, which your picaxe program will have to identify and respond appropriately to.

There's not much that can be done to simplify this if you want to use a browser on your phone. An alternative would be to write a special program which runs on the phone and sends messages of some sort to the esp (e.g., UDP), which the picaxe must still capture, parse, and respond to.
 
Last edited:

hippy

Senior Member
I'm not sure that asking the same question in a different way (or with a different thread) is going to get you a different answer.
I suppose the nuance here is using an ESP programmed as a bridge rather than using it in AT command mode.

There was an example of doing that in the Where's the Wizard? thread -

https://picaxeforum.co.uk/threads/wheres-the-wizard.31896/#post-331331

There probably aren't that many examples out there for doing this because most ESP2866 users will be using it as a micro but those projects are good starting points - Find an ESP2866 project which turns a LED on and off then replace what it's doing, its digitialWrite() commands and similar, with serial output commands which send data to a PICAXE which then acts on those commands. Which is what 'kfjl' probably did in the above link.

The big picture challenge is as below -

Browser / App -> WiFi -> Router -> WiFi -> ESP -> Bridge -> PICAXE -> LED

Where that 'Bridge' part lives is the big question. Separately as shown, as part of the ESP or part of the PICAXE. Plus of course how to get status from the PICAXE back to the browser or App.

It's a multi-faceted problem, with no single definitive solution, but there are 'how I did it' examples and implementations.
 

lbenson

Senior Member
Since this has been an enlightening and instructive exercise, I'm sorry to say this (since it touts a different product), but I was tempted to say at post #2 that the easiest solution (in my experience) to the original question of phone to controller via wifi (which before editing didn't mention a PICAXE) is to use Annex Basic on an ESP8266 or ESP32 (depending on how many pins you need to control):

Mods feel free to delete this post.
 

Electronics Learner 123

Well-known member
Since this has been an enlightening and instructive exercise, I'm sorry to say this (since it touts a different product), but I was tempted to say at post #2 that the easiest solution (in my experience) to the original question of phone to controller via wifi (which before editing didn't mention a PICAXE) is to use Annex Basic on an ESP8266 or ESP32 (depending on how many pins you need to control):

Mods feel free to delete this post.
Could this be used in conjunction with the Picaxe e.g send variables etc...
 

lbenson

Senior Member
Could this be used in conjunction with the Picaxe e.g send variables etc...
Could be, but I wouldn't personally do it that way, and on this picaxe site I wouldn't want to get into the question of how to program the ESP in Annex to do so, even if it was intended to talk to a picaxe. The AT command interface is available out-of-the-box with no programming of the ESP. Annex is a whole language & development system in itself.
 

Electronics Learner 123

Well-known member
Could be, but I wouldn't personally do it that way, and on this picaxe site I wouldn't want to get into the question of how to program the ESP in Annex to do so, even if it was intended to talk to a picaxe. The AT command interface is available out-of-the-box with no programming of the ESP. Annex is a whole language & development system in itself.
In terms of AT commands, I know that the are used to connect to the WiFi and can be used to receive data( not sure how to do that yet?) how does the Picaxe use this code, does it read from serial?
 

lbenson

Senior Member
In terms of AT commands, I know that the are used to connect to the WiFi and can be used to receive data( not sure how to do that yet?) how does the Picaxe use this code, does it read from serial?
Hippy's referenced code does all this. Communication with the ESP Tx and Rx pins are through the picaxe "hardware serial" pens, with input to the picaxe going to the scratchpad memory via hardware serial background receive; see HSERSETUP, HSERIN, and HSEROUT commands in manual 2.
 

lbenson

Senior Member
Here is my solution for using a picaxe to serve a web page to browser on phone or pc or tablet.
 

geoff07

Senior Member
Greetings, it has been a while. But what else to do in lockdown once the grass is cut etc.?

I too have been playing with ESP-01s, in order to add wifi to my home automation (based on numerous Picaxe chips). Here is a working program that implements the allaboutcircuits example using thingspeak (correctly). It is deliberately verbose and certainly isn't optimised for e.g. power, but I guarantee it works!

You will need a programmer as per the allaboutcircuits V2 design (I built mine on veroboard rather than a breadboard as it will be needed several times), and Termite, and in my case an 08M2 protoboard and fddi cable, and an account on Thingspeak (Mathworks). There are a few elephant traps (baud rates, bugs in 'working' examples, etc.) but this code is working as I type. I acknowledge the input of others, but I have made the code readable, working, and a bit more explanatory when things go wrong. You will need to set the ESP-01s to 9600 baud. I can provide a bit more info if anyone is interested.
 
Last edited:
Top