Lets Talk!

(or 'just what the hell is going on, here?')

In this section you will learn

back to Main

Remember, hand written notes are really important.

Make notes on things that trip you up, things you understand in your own words, things that you want to look further into or places to look at later (python programming tutorials etc) and your findings as you go through.

The more work you put in here that we can use to prove you've been learning things, the less other work you have to do! Be kind to yourself, spend a little extra time on this, or spend a lot of time later because you didn't..

What actually is this thing?

So, you've learned to program in Python. And to do that you've done some on the computer through VS Code, and more importantly you've also done it directly on the ESP8266.

So, what is an ESP8266? Well according to the great gods of the internet an ESP 8266 is:


ESP8266

From Wikipedia, the free encyclopedia

The ESP8266 is a low-cost Wi-Fi microchip, with a full TCP/IP stack and microcontroller capability, produced by Espressif Systems in Shanghai, China.

The chip first came to the attention of Western makers in August 2014 with the ESP-01 module, made by a third-party manufacturer Ai-Thinker. This small module allows microcontrollers to connect to a Wi-Fi network and make simple TCP/IP connections using Hayes-style commands. However, at first there was almost no English-language documentation on the chip and the commands it accepted. The very low price and the fact that there were very few external components on the module, which suggested that it could eventually be very inexpensive in volume, attracted many hackers to explore the module, the chip, and the software on it, as well as to translate the Chinese documentation.

The ESP8285 is an ESP8266 with 1 MiB of built-in flash, allowing the building of single-chip devices capable of connecting to Wi-Fi.

The chip first came to the attention of Western makers in August 2014 with the ESP-01 module, made by a third-party manufacturer Ai-Thinker. This small module allows microcontrollers to connect to a Wi-Fi network and make simple TCP/IP connections using Hayes-style commands. However, at first there was almost no English-language documentation on the chip and the commands it accepted. The very low price and the fact that there were very few external components on the module, which suggested that it could eventually be very inexpensive in volume, attracted many hackers to explore the module, the chip, and the software on it, as well as to translate the Chinese documentation.

The ESP8285 is an ESP8266 with 1 MiB of built-in flash, allowing the building of single-chip devices capable of connecting to Wi-Fi.


..well, wasn't that gripping. Thats not a description, that's an epitaphe!

Right, well here's my explanation of what an ESP8266 is.

It's the main board on lots of little cheap boards. The other bits on the board they are often attached to are optional stuff to make it easier to program, give you more memory or better access to the programmable pins the ESP 8266 lets you play with.

Talking about pins, the pins you can play with on a embedded board like this or an Arduino or Raspberry Pi are called GPIO. That stands for General Purpose In/Out. What it means though, is being general purpose we are allowed to do things with them, and being in and out means we can either have them send signals, or receive them.

The really important bit for us (and the bit you've already been playing with) is that they are very easy for newcomers to get going programming them.

The other stuff, like ease of programming is about whether you can plug a usb cable straight in, whether it has a reset button, has additional memory etc.

Now the thing about the ESP8266 that makes it so awesome in comparision to an Arduino is that it has WiFi on the board. Usually you would need to get an additional Arduino Shieldy-thing to sit on your Arduino to do this, but because the whole design of the ESP8266 is based around a micro-controller processor sat around a WiFi component, doing Internet Of Things (IOT) is stupidly simple. You can easily write a program that listens for a web signal over WiFi, and when it sees it it turns on a LED connected to it's pins that are just variables in your program, and I don't mean that in any general 'when you have learned what compiling your own kernel' means or 'when you can do the elite codes' sense, I mean now, today.

Wait, it does what?

Yeah, those GPIO pins are just variables the processor already knows about. All you need to do is say 'pin number something or other you are an input' or 'you other pin, you are an output'. If you've set a pin as an output pin and tell that pin to be on(), it turns the pins signal on meaning it puts some voltage on there, if you tell it to be off() it turns the signal off meaning it stops any voltage on it.

If a pin is set to an input and that pin receives a voltage (like it a switch is pressed with 3.3 volts on it) then the processor sees that signal from the pin and if asked 'have you been activated?' it will reply 1, whereas if you dont press the button and ask the pin, it will reply 0. Just think of that in terms of truthiness where a 1 is True (or yes) and 0 is False (or no).

Can I make it do that?

Yeah, you ready, it's really simple.

```python

Imports are always at the top.

They pull in additional things for you to use

in your Python application.

The Machine library gives us access to the pins.

from machine import Pin

Set a new variable of p0 to pin 0,

and set it to ouput mode

p0 = Pin(0, Pin.OUT) # create output pin on GPIO0

p0.on() # set pin to "on" (high) level p0.off() # set pin to "off" (low) level p0.value(1) # set pin to on/high

This pin is pin 2 and set to an input

p2 = Pin(2, Pin.IN) # create input pin on GPIO2

print(p2.value()) # get value, 0 or 1 ```

Now look at that script again, but ignore the comments. 7 lines. In those seven lines we've covered everything we've talked about so far.

What else can it do?

Well, a lot, and not a great deal at the same time. This is one of those 'its as big as you imagine it' things. It's also why I like to occasionally spend silly money on loads of little Arduino component breakout boards, cos if it's a LED then I can plug it in without scrabbling around for a 220 ohm resistor cos the little board already has one on it!

So, now it's fun time. In Section_1 - Hello World I spammed you with an additional section on VS Code, whereas in this Assigment, all you've had to do so far is read..

Wait, what? ...that's quite a lot, where do I start?

Making an LED turn on, and then off again, and then on, and then off again, and then on, and then off again, and then ... well you get the point.

Onbligatory Blinky