If you follow my blog, you probably noticed that I use different online services to make my PCBs… it’s a way to test them in terms of quality and production time.
On the advice of my friend Mauro, I recently chose PCBWay to produce some PCBs for my future projects.
The procedure for sending a new order is very simple; first you have to enter some information about your PCB:
then, in the next page, you can configure som specific details of your printed circuit board (color, material, finishing, copper size…). It’s interesting the possibility – not often available – to choose the color of the silkscreen:
Once selected the production mode (nomal = 2-3 days or express = 24h) and the shipping method, you can add the PCB to your shopping cart and upload the Gerber files of your project. PCBWay doesn’t offer the CAM jobs for Eagle, but I verified that they accept files in the same format of Seeedstudio. If you use Eagle, you can therefore follow my tutorial to create the needed Gerbers.
Before being able to complete the payment and send the PCB to the factory, the files must pass a manual check. Yes, PCBWay manually verifies every file you upload… this process requires only some minutes and it’s definitely an added value: in one of my orders I made a small mistake and I was promptly contacted by a PCBWay engineer with an email reporting the mistake and asking me for the correct file.
When the order is in production, you can follow the progress in your personal area:
Even the website displays every step of the production process:
The quality of the PCBs I received is very good, certainly comparable to other services I used in the past. The price also is alined to the other manufacturers and PCBWay does offer an entry price of 5€ for 10 PCBs (10x10cm max).
Wemos is a chinese manufacturer of IoT products, well known for its D1 Minifamily, that includes boards based on the ESP-8266EX chip and expansion shields.
Some weeks ago, Wemos announced a board based on the new ESP32 chip, named LOLIN32. This board hosts an ESP-WROOM-32 module and can be powered by a single cell (1S) LiPo battery. The board can also recharge the battery thanks to a circuit based on the TP4054 chip.
I brought a LOLIN32 board from Wemos’s official store on Aliexpress. The board is shipped inside an anti-static bag, with a label with your name:
Although this board has the “wemos” logo printed on it, it actually looks like a clone of the D-duino-32 project by Travis Lin: unlike the LOLIN32 indeed this board does not include the LiPo battery connector and the charging circuit while it adds a 0.96″ OLED display.
Here’s a visual comparison between the two boards:
The advantage of purchasing an original Wemos card is the availability of the electrical schematic, some tutorials and a support forum… all that is missing for the clone board (how is the OLED display connected?). My suggestion is therefore that if you want to buy a Wemos board, you should get it from the original store.
If instead you are interested in a board with a OLED display, why not buy it directly from the designer’s tindie page, to support its development?
STM32 is a family of 32bit microcontrollers manufactured by STMicroelectronics and based on the ARM Cortex M core.
The STM32 family is divided into different lines of microcontrollers (L0-1-4, F0-1-2…) depending on their features and the use they are designed for:
These microcontroller are widely used in the industrial world… for example both Pebblewatches and Fitbit bracelets are based on STM32 MCUs.
If you’re interested in quadricopters or drones, you probably have heard or used F1, F3, F4…flight control boards. The board name (“F…”) indicated indeed the STM32 microcontroller they are based on.
Thanks to the work made by the stm32duinocommunity and to the support of ST itself, starting from the past June STM32 microcontrollers can be easily used with the Arduino IDE and it’s also possible to take advantage of most of the libraries available for Arduino.
I decided to buy a minimal development board based on the STM32F103C8T6 microcontroller (these boards are sometimes known as blue pills); let’s see how to use it with Arduino.
Many boards are sold unprogrammed: the first thing to do is therefore to program a bootloader, that is a small program which will allow to upload the “real” program via USB port.
You have also to enable the programming mode, moving the first jumper (labeled BOOT0) to position 1:
Now you need a software to flash the file with the bootloader into the chip. If you’re under Windows, you can download the Flash Loader from ST’s official website: after having registered (for free) you’ll receive the download link via email.
The bootloader is developed and maintained by Roger Clark and it’s available in his Github repository. For STMF1 boards there are several binary files, depending on the PIN the onboard led is connected to. My board uses P13, so I downloaded the file generic_boot20_pb13.bin.
Run the Demonstrator GUI program and select the serial port your adapter is connected to:
If all the connections are ok, the software should be able to detect the microcontroller:
Now you can select the specific MCU your board uses:
then select the file with the bootloader and program it. To be sure, you can ask the software to perform also a global erase of the memory:
The program will flash the chip and, when complete, will confirm the operation with a message:
If you now move back the BOOT0 jumper to the original position, you should see the led blink: this means that the bootloader is running and can’t find a program to execute… now it’s time to configure the IDE.
Open your IDE and select File – Preferences. Type the following address in the Additional Boards Manager URLs field:
Search STM32F1 and install the corresponding Corespackage:
You’re almost ready to compile and run your first program…
Connect the dev board to your PC using an USB cable and verify how it is identified.
It may happen that Windows cannot correctly identify the board and displays it as Maple 003, is this case you have to install the correct drivers:
Download the following files from Clark’s repository:
Run the two .bat:
now Windows should identify the board correctly:
Sometimes Windows cannot see the additional serial port of the board. To solve the problem, you can try to program on the board a simple sketch that uses the Serial object. Open for example the blink sketch and change it as it follows:
Program the sketch choosing BluePill F103C8 as board and STM32duino bootloader as upload method.
Once the sketch is programmed and executed, Windows should detect and install the new COM port:
You’re done, now the board is fully integrated with the Arduino IDE:
One of the most popular projects among the ones included in my tutorial about the enc28j60 chip is fore sure WebRelay. This project allows to control an output pin of Arduino using a simple web page, designed to be accessed also using your smartphone. Today I’m going to show you how to implement a similar project with the esp32 chip; it’s also the opportunity to teach how to write a TCP server, especially a web server.
As you know, the esp-idf framework uses the lwip library to manage network communication. This library offers different abstraction levels: the programmer can decide to work on the raw packets or to leverage pre-build components.
To develop my TCP server, I decided to use one of those pre-build components, the Netconn API.
Using Netconn API it’s very easy to implement a server and the required steps are described below:
The netconn_new() method creates a new connection and returns a a pointer to struct netconn which represents the connection:
The parameter defines the connection type… the most common ones are NETCONN_TCP for a connection using the TCP protocol and NETCONN_UDP for a connection using the UDP protocol.
To use the connection in server mode, you have then to associate (bind) it to a specific port… for example a webserver normally listens on port 80 (443 if HTTPS):
The second parameter (NULL above) allows to bind the connection to a specific IP address and may be useful if the device has more than a network interface. If you pass NULL (or the equivalent IP_ADDR_ANY) you ask the library to bind the connection to any available interfaces.
Now you can start listening on that port with:
Working with a client connection
With the netconn_accept() method, your program can accept a new incoming connection:
The method returns a pointer to a new struct netconn that represents the connection established with the client. This method is blocking: the program is stopped until a client makes a connection request.
Once the connection is established, you can use the netconn_recv() and netconn_write() methods to receive or send data to the client:
Likewise, the netconn_write() method accepts, as last parameter, a flag to indicate whether or not to copy the buffer content before sending it. To save memory you can therefore, if you’re sure that the buffer won’t be modified by other theads, use NETCONN_NOCOPY as flag:
When the communication with the client is complete, you can close the connection and free the buffer:
What you learned so far can be applied to every TCP server. If you want to communicate with an Internet browser, you have to “talk” the same language, that is the HTTP protocol.
In the example program (available on Github) I implemented a very minimal version of that protocol. When you type an address in your browser (for example www.google.com), the browser connects to Google server and sends a request with the form:
The request can have different fields, but the first line always contains the name of the requested resource (html page, image…). In particular if you access the homepage of the website the request will simply be GET /.
The website published by the esp32 chip to control the relay consists of only two pages:
off.html, displayed when the relay is off
on.html, displayed when the relay is on
Each page contains a label (“Relay is ON|OFF“) and an image. The image itself is a link to the other page and when you click on it, the relay status is also changed:
The program identifies the resource to be sent analyzing the first line of the request with strstr():
An HTTP server responds to the browser by first indicating the result of the request. If ok, the return code is 200:
then it returns the media type of the resource and finally it sends the resource file. In this example, the possible media types are:
text/html for HTML pages
image/png for images
A webserver it normally stores the resouces for the website it publishes on an external device (memory card, hard drive…). For simple projects, you may consider to include all the content inside your program.
For example in my code HTML pages and HTTP protocol messages are defined as static arrays:
The syntax is _binary_filename_start|end, replace “.” with “_” in the filename. Having pointers to both the start and the end of the resource content, it’s easy to send it with the netconn_write() method:
Today we start building the chassis kit from Banggood that will become the robotic platform we’ll play with in the next posts…
But first, remove the protective paper from all the acrylic parts:
Let’s mount the motor on the chassis. You need the motor, two screws with their nuts, two mounting plates and the plastic wheel for the encoder. Insert the wheel on the motor shaft and place the two plates in the corresponding chassis holes:
For convenience, you can solder two wires (red and black) to the motor before mounting it on the chassis. Then secure the motor to the plates using screws and nuts. Make sure that the encoder wheel is inside:
With the help of a screwdriver, tighten the two screws so that the motor is securely fastened to the base:
Do the same for the second motor and make sure that the wheel can freely move and does not touch the chassis:
Complete the assembly inserting the two wheels in the motor shafts:
Now the caster, that is the front wheel. You can mount it on the chassis using 4 screws and nuts and the holes already present:
After having completed the assembly, you will notice that the caster is lower than the rear wheels; the robot is tilted forward. You can fix it by adding the 4 spacers between the caster and the base::
In today’s tutorial you’ll learn how to permanently store information, so that they are preserved even if the esp32 chip is reset or power is removed.
NVS (Non Volatile Storage) is a library included in the esp-idf framework that allows to store information (in the form of key/value) in the flash memory, the content of which is not erased when you reset the chip or remove the power.
If you remember, in a previous post I explained how the external flash memory is organized. The main purpose of that memory is for sure to store the program that will be executed by the esp32 chip. However, it’s possible to divide the flash memory in partitions: the framework offers some ready-to-use partition tables but you’re free to define custom ones.
If you use the default partition table (“Single factory app, no OTA”), you may notice that it contains a partition of type data and subtype nvs:
The default size for that partition is 24Kbyte.
Thanks to the NVS library, you can store custom data into that partition. Information is organized in key/value pairs; a label (= key) with a maximum length of 15 characters is assigned to each value:
You can store different types of data: from numeric values to text strings and byte sequences (blob, binary large object). You’ll learn that the library provides specific methods based on the type of data you want to store or retrieve.
To be able to use the library in your code, first include the following headers:
The first step to use the nvs partition is to initialize the library, with the command:
esp_err_t err = nvs_flash_init();
The command returns ESP_OK if successful; on the contrary it returns one of the error codes defined in the nvs.h file (see below). In particular, if the partition was resized or changed, you may get the ESP_ERR_NVS_NO_FREE_PAGES error code. This error can be resolved “formatting” the partition.
First you have to identify the nvs partition in the flash memory:
Because of you cannot know a priori the size for string or blob values, you can do a “trick”: first call the nvs_get_string() method passing NULL as pointer to get the length of the value, then allocate a variable with the correct size and finally call again the method passing that variable to get the value:
For this tutorial I wrote a program that allows, using a simple command line, to store and retrieve information from the nvs partition. The source code is available on Github, here’s a video that shows how it works:
On this blog I published several electronic projects and tutorials but I realized that none of those is about robotics; for this reason I’m going to start – with this post – a tutorial for dummies to teach how to build a small robot and how to program it to do different tasks, like avoid obstacles, follow a line, receive commands…
In all the examples so far, we used the esp32 chip in STAtion Mode, that is as a client which connects to an existing wifi network. In a previous article I explained in details how the different components of the esp-idf framework interact to establish the connection and how to use events to syncronize the tasks of your program.
Today you’ll learn how to configure the esp32 chip to publish its own wifi network, similar to an access point. This mode is indeed named SoftAP.
Every device connected to an IP network must have its unique address. You can statically assign the address or leverage a network service (DHCP, Dynamic Host Configuration Protocol) that dynamically assigns them. The main advantage in using the DHCP service is that you don’t need to know in advance – when connecting to a network – the correct settings to apply (IP address, netmask, gateway…); this is the reason why normally the device which manages the network also offers a DHCP server:
The esp-idf framework does include a DHCP server. To use it in the network you’re going to create, you have to:
stop the service if it’s already running – tcpip_adapter_dhcps_stop()
statically configure the network interface of the esp32 chip – tcpip_adapter_set_ip_info()
start the service – tcpip_adapter_dhcps_start()
The esp-idf framework uses two different interfaces depending if the esp32 chip is in station mode or in SoftAP mode (TCPIP_ADAPTER_IF_STA e TCPIP_ADAPTER_IF_AP). Make sure you’re configuring the correct one based on the mode you’re planning to use.
For example, to assign the address 192.168.10.1/24 (/24 corresponds to 255.255.255.0 netmask) and run the DHCP server:
Three are the main events available when working in access point mode:
SYSTEM_EVENT_AP_START, when the stack completed the start process (after esp_wifi_start)
SYSTEM_EVENT_AP_STACONNECTED, when a new device connects to the access point
SYSTEM_EVENT_AP_STADISCONNECTED, when a device disconnects
In the example, the events are notified using different event bits:
case SYSTEM_EVENT_AP_START:printf("Access point started\n");break;case SYSTEM_EVENT_AP_STACONNECTED:
xEventGroupSetBits(event_group, STA_CONNECTED_BIT);break;case SYSTEM_EVENT_AP_STADISCONNECTED:
In SoftAP mode, the esp32 chip supports different authentication modes:
open configures a wifi network with no authentication, while all the other modes offer some security, from the “weak” ones (WEP, now easily hackable) to the strongest ones (WPA2). Personally, I always use the WPA2_PSK mode, which offers high security and authentication, using a shared password (PSK = PreShared Key).
Some authentication modes require a minimum password length. In particular, WPA and WPA2 require a password at least 8 characters long; if you specify a password too short, the esp_wifi_set_config method will return an error.
List the connected devices
You can get the list of the devices connected to the access point with the esp_wifi_ap_get_sta_list() method, which updates a wifi_sta_list_t struct: