The board will automatically create a WiFi AP when it is connected: SSID: EspruinoDev PW: EspruinoPW
Connect to this WiFi and the Espruino Board will be the default gateway. Most likely something like 192.168.4.1
Plug the guy into the Computer. And get all available serial ports:
ls /dev | grep tty
This should get you a list all serial ports.
Hopefully not too many, either way find the one which corresponds to the USB device
The documentation says on Mac it should always be /dev/tty.usbmodem1234 but who knows for sure!
You can use this Chrome App to write JS and load it onto the board: https://chrome.google.com/webstore/detail/espruino-web-ide/bleoifhkdalbjfbobjackfdifdneehpo?hl=en Click the top left Connection Icon and choose the serial port (if using USB) OR Go to Options -> Communications -> Connect over TCP Address
Or you can use this node.js CLI tool (my preferred method): https://www.npmjs.com/package/espruino The command for this would be
npm install espruino --save
FOR WIFI SETUP: $ npx espruino -p tcp://192.168.1.121 -b 115200 --watch app.js
FOR USB SETUP: $ npx espruino -p /dev/tty0 -b 115200 --watch app.js
You now know how to connect to the Espruino Board, hurray! It is time to flash some JavaScript onto it, so setup the Web IDE or the command line tool and write the following
const wifi = require("Wifi");
wifi.connect("YOUR HOME WIFI SSID", {password:"YOURHOMEWIFIPASSWORD"}, (err) => {
console.log('I AM CONNECTED!')
console.log(wifi.getIP())
});
wifi.stopAP();
wifi.setHostname("Oussamas ESP8266");
wifi.save();
If the code was successfully flashed onto the Board, then your ESP8266 is now connected to your home WiFi and you can throw away that USB cable forever!
Try to find it in your local network before that though, to avoid any awkward cable shopping afterwards.
OLED screen Documentation: https://www.espruino.com/SSD1306 Graphics Library Docs to write onto that OLED: https://www.espruino.com/Graphics General API reference for Espruino: https://www.espruino.com/Reference#software
let flash = false;
setInterval(() => {
flash = !flash;
// Turn the D4 Pin on the board ON or OFF
digitalWrite(NodeMCU.D4, flash);
}, 500);
function displayReady(){
// Increase Font Size
g.setFontVector(40);
let i = 0;
setInterval(() => {
// Clear the previously drawn stuff
g.clear();
// Draw i to the screen
g.drawString(i++);
// Write the buffered actions to the screen
g.flip();
}, 100);
}
I2C1.setup({ scl : NodeMCU.D3, sda: NodeMCU.D2 });
const g = require("SSD1306").connect(I2C1, displayReady);
This is a bit tricky because the ESP8266 has only one Analog input (which both the knobs need) So they are turned off and on depending on what you want to do
function getKnobReading(side) {
if (side === 'left') {
digitalWrite(NodeMCU.D5, false);
digitalWrite(NodeMCU.D6, true);
} else {
digitalWrite(NodeMCU.D5, true);
digitalWrite(NodeMCU.D6, false);
}
// Round the analog reading to the second decimal place, because
// there is a lot of noise in the reading
return Math.round(analogRead() * 100) / 100;
}
setInterval(() => {
console.log("Left Knob", getKnobReading('left'))
console.log("Right Knob", getKnobReading('right'))
}, 200)