Instructables View Counter + ESP8266 Guide
by ThomasVDD in Circuits > Electronics
3425 Views, 30 Favorites, 0 Comments
Instructables View Counter + ESP8266 Guide
Subscriber counters for Youtube and Facebook are quite common, but why not make something similar for Instructables?
That's exactly what we're going to do: in this instructable, we'll make an Instructables view counter!
The views will have to be captured from the interwebs, so we'll use the common (and cheap) ESP8266 WiFi module to get the required information. It needs some configuration, but I'll go through all the steps required to get it up and running.
To keep the project as accessible as possible (i.e., not requiring a 3D printer, laser cutter or particle accelerator), I decided to use Lego for the case! So get out that bin of Lego and let's get building!
Parts & Tools
Parts
- ESP8266 ESP-01
- MAX7219 7 digit LED display module
- 3.3V compatible FTDI breakout (programmer)
- Pin headers
- 4x 10k Ohm resistor
- 2x Push button
- 2x 10uF capacitor
- 3.3V regulator (LM1117-3.3V)
- USB cable
- Lego!
Total cost: < 10$
Tools
- Soldering iron
Electronics
Let's begin the project by building the circuit.
The electronics of the project are not very complicated, but the ESP8266 module requires some special treatment to get it to work. So first of all, what is this ESP thing all about?
The ESP8266 is best known as a low-cost WiFi chip, but it also has a full fledged microcontroller unit capability. This makes it ideal for projects that require WiFi and controlling of external components like our 7 segment display. The programming is done with a USB to serial converter, also called an FTDI converter.
Schematic
The components can simply be connected as in the schematic, but a bit more information is given here.
First of all, the ESP8266 operates from 3.3V, while the display (and the USB which we'll use for power) operates on 5V. This means we'll need a voltage converter to transform the 5V of the USB into 3.3V for the ESP8266.
When powering up the ESP8266, it will enter one of its "boot modes", depending on the voltage at its IO pins. In other words: if we want it to execute our code when it boots, we'll have to configure this!
For program execution this means:
- CH_PD to VCC
- RST to VCC
- GPIO0 to VCC
- GPIO2 to VCC
While for programming the device, this translates to :
- CH_PD to VCC
- RST to VCC
- GPIO0 to GND
- GPIO2 to VCC
As can be seen, the only difference is the state of the GPIO0 pin. Hence, we'll us a push button to connect GPIO0 to GND when programming.
After booting, the pins can be used freely, in our case for 2 things:
- As an input: there is a button connected to GPIO2.
- Driving the screen. Since it needs more than 2 signals, the TX and RX line will also be used as IO.
Now that we have the theory of operation out of the way, we can translate this into a physical design.
PCB
To make the PCB, I designed a perfboard/stripboard layout in KiCad (an open source PCB layout software). By setting the grid spacing to 2.54mm (0.1 inch), you can make layouts which can be soldered onto stripboard.
This makes it super easy to solder the electronics together: simply print out the design (included as a PDF) and copy the design on the stripboard. Use header pins to connect the screen, FTDI and ESP8266.
After soldering, cut the perfboard to the right size and plug in all the components.
With the electronics soldered together we can blow life into them with some code!
Programming the ESP8266
Setting up the libraries
Before we can upload any code to the board using the Arduino IDE, we will need to add its libraries. This can be done by following the next steps:
- Go to File>Preferences and paste following link in the "Additional board manager URLs" box: http://arduino.esp8266.com/versions/2.3.0/package_esp8266com_index.json
- Go to Tools>Boards>Boards Manager and search for ESP8266
- From this window, install the most recent package
- Restart the IDE
- From Tools>Boards, select "Generic ESP8266 Module" as a board
- Open the sketch and render it (ctrl+R) to see if the board has been added correctly.
Uploading the code
To program our device, we will need to put it into programming mode and connect it to the FTDI breakout board. This can be done by pulling the appropriate pins to VCC or GND and making the connections as listed below.
- CH_PD to VCC
- RST to VCC
- GPIO0 to GND
- GPIO2 to VCC
- RX to TX of FTDI
-
TX to RX of FTDI
Fortunately, all connections those connections are already present on our PCB. I tried it on a breadboard first, and as you can see, it is a bit clumsy. So to upload code:
- Remove the display and plug in the FTDI
- Hold down the program button when connecting the USB cable
- Upload the code. After uploading "Set net" should be displayed
Possible errors
You might get an error when uploading like "error: espcomm_upload_mem_failed", simply reupload the code.
If the display remains blank on powerup, also reupload the code.
Running the code
To run the code we just uploaded, the programming mode should be disabled by pulling the GPIO0 pin to VCC. Or in our case, power up the device without pressing the program button.
With the code uploaded and running, we can now configure our viewcounter!
Setting Up the Viewcounter
The configuration of the viewcounter is done via a webpage interface. This allows to change the settings on the fly instead of having to reupload the code each time.
Configuring the web server
- Power up the unit and wait for "set net" to be displayed
- Press the Mode button, the device will show "setup"
- On your PC, go to your WiFi networks and select "Instructables Hit Counter"
(When asked for a password, enter 'password'.) - A browser window should open (otherwise open one yourself and type in 192.168.4.1)
- A page opens, press "Configure WiFi"
- Choose a network and type in your password. Fill in a static IP, gateway and subnet
- Hit save, a confirmation page will appear
Now that the ESP8266 is connected to our WiFi network, we can fill in our Instructable credentials.
User Setup
- Open a browser and type in the static IP you choose in the previous step.
- Go to the "User setup" tab
- Fill in your Instructables name and save
- To see the views of a specific Instructable, follow the instructions on the page
- Hit save, your views will now be displayed!
- For more options, explore the settings ;)
The counter is now fully functional, but still looks a bit dull. Let's change that by making an awesome case!
Note
The code of this project comes from this awesome guy: https://www.instructables.com/id/Instructables-Hi... All credit for the code goes to him, I am merely using it to make my own version of the project. The main reason I write this is because I had to puzzle some things together to make it work (like how to program the ESP8266, adding the libraries, getting the instructables ID, making the PCB, ...) and wanted to make a complete standalone guide.
Casing
This is the part where you can get super creative. Any case can work, but making a nice one can make or break a project. Therefore, I decided to make mine out of Lego!
Mounting the screen
To fix the screen in place, I found that a "Lego panel without side support" fits the screen perfectly. There is only one downside: it's twice as wide as I'd like... Fortunately, this is easily solved by cutting it in 2. We now have a nice mount for the display, and a good starting point for the whole case!
Making the letters
To make it more obvious that this is a view counter, I wanted to include a label with "views". But then I thought, why use a stupid label when you can make letters out of Lego? So that's what I did!
I included a close up off the letters such that they are easier to replicate.
Making the robot
I was looking for something to finish off this build, and stumbled across this awesome instructable: https://www.instructables.com/id/Lego-Instructable...
The instructables robot built out of Lego, the perfect companion for the view counter! I won't go into the detailed steps of making it here, since it is explained step by step in the original instructable.
Our little companion is the finishing touch to our case; we're done!
Test & Enjoy!
We're done! The only thing left to do is to test our new view counter.
Connect it to a USB port and admire your views!
I hope you liked the project and are inspired to make something similar.
Feel free to check out my other instructables: https://www.instructables.com/member/ThomasVDD/