Hi everyone,
I've started to play around with example sketches in the Arduino IDE and upload them to my ESP32-C3-Dev module, but I'm butting error messages.
I have added the ESP board manager to the IDE. I have connected the board to my PC (WIN10) via USB.
Below is the error message I get when trying to upload the BLINK example sketch.
I have looked at the URL in that message and there was something about needing Python and pyserial installed.
I have installed Python OK, but when I attempt to install pyserial (following some YT videos), I am getting the following message in Command Prompt.
I have even uninstalled Python and downloaded the pyserial file again, with the same result.
I have also tried different USB-A to micro USB leads in case I was using a "charging only" lead, but that's not the issue.
Thoughts anyone?
Is there a way to test the connection to the board from the PC, maybe via a command window?
I am a complete novice at all this including Python so be gentle!
Cheers,
Ian
Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice
I am a complete novice at all this including Python so be gentle!
Are you using Windows, Linux or a Mac?
I have looked at the URL in that message and there was something about needing Python and pyserial installed.
Bill mentions a pyserial problem.
https://dronebotworkshop.com/esp32-intro/
If that is your source of code then it doesn't use Python it uses Arduino C++.
I am using the Arduino IDE.
Just found the issue.
There was a missing driver for the USB to UART (or something like that).
Have installed that, and the BLINK sketch is working! YAY!
Now to try some more example sketches.
Cheers,
Ian
Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice
I am using the Arduino IDE.
Just found the issue.
There was a missing driver for the USB to UART (or something like that).
Have installed that, and the BLINK sketch is working! YAY!
Now to try some more example sketches.
Cheers,
Ian
That means the CP2102 driver was missing. Good to know that it is working now.
Have installed that, and the BLINK sketch is working! YAY!
Congrats 🙂
Now to try some more example sketches.
Maybe you will get hooked on programming 🙂
Are you going to learn to understand them?
A program is essentially a list of instructions and you need to know what each instruction does although you do not have to know how it is done.
For your project the next thing you need to do is install the ESP-NOW library. You can then do things like check if a button on one board in pressed and if it is send a message to the other board to lock or unlock its drum.
Just to let you know I am still working on a readable working example which you can test on your hardware.
Unless someone has already given you a working solution which you have been able to implement?
Let me know when you have successfully installed the ESP-NOW library.
When you have done that you need to know their MAC address. You can find that out by running this program on each board. I found the one on Bill's tutorial didn't work anymore but this one does.
/* Rui Santos & Sara Santos - Random Nerd Tutorials Complete project details at https://RandomNerdTutorials.com/get-change-esp32-esp8266-mac-address-arduino/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ #include <WiFi.h> #include <esp_wifi.h> void readMacAddress(){ uint8_t baseMac[6]; esp_err_t ret = esp_wifi_get_mac(WIFI_IF_STA, baseMac); if (ret == ESP_OK) { Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x\n", baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]); } else { Serial.println("Failed to read MAC address"); } } void setup(){ Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.STA.begin(); Serial.print("[DEFAULT] ESP32 Board MAC Address: "); readMacAddress(); } void loop(){ }
You can test if the two boards are communicating by loading the program below on both boards but with the MAC addresses of the other board.
This is what I earlier called "template" code which you can tailor for different implementations and I can show how to tailor it. All this template code does is send an ID message to the other board in the form of a message and you can change the other copy message to "Hello I am the GREEN board". You need both versions running on its own board with the window of each version displayed and size them to both fit on your computer screen as shown and explained in Bill's tutorial. You then start the Tools>Serial Monitor in the Arduino IDE to view their outputs.
You do not have to have any buttons, LEDs or servo motors connected to the boards to test the code.
#include <esp_now.h> #include <WiFi.h> uint8_t broadcastAddress[] = {0x34, 0x98, 0x7A, 0xBC, 0xC8, 0x3C}; // grn board //uint8_t broadcastAddress[] = {0x58, 0xBF, 0x25, 0x9F, 0x12, 0xF8}; // red board // Variable to store if sending data was successful String success; typedef struct metData { char msg[32]; } metData; // Create a metData to hold outgoing readings metData outgoing; // Create a metData to hold incoming readings metData incoming; esp_now_peer_info_t peerInfo; // Callback when data is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("\r\nLast Packet Send Status:\t"); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); if (status ==0){ success = "Delivery Success :)"; } else{ success = "Delivery Fail :("; } } // Callback when data is received void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&incoming, incomingData, sizeof(incoming)); Serial.print("Bytes received: "); Serial.println(len); } void setup() { // Init Serial Monitor Serial.begin(115200); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); // Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // Once ESPNow is successfully Init, we will register for Send CB to // get the status of Trasnmitted packet esp_now_register_send_cb(OnDataSent); // Register peer memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK){ Serial.println("Failed to add peer"); return; } // Register for a callback function that will be called when data is received esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv)); } void loop() { // ********** FILL outgoing struct with data to send ***** strcpy(outgoing.msg, "Hello I am the RED board"); // Send message via ESP-NOW esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &outgoing, sizeof(outgoing)); if (result == ESP_OK) { Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); } // display incoming data Serial.print("incoming message ="); Serial.print(incoming.msg); // act on incoming data delay(5000); }
Have installed that, and the BLINK sketch is working! YAY!
Congrats 🙂
Now to try some more example sketches.
Maybe you will get hooked on programming 🙂
Are you going to learn to understand them?
A program is essentially a list of instructions and you need to know what each instruction does although you do not have to know how it is done.
For your project the next thing you need to do is install the ESP-NOW library. You can then do things like check if a button on one board in pressed and if it is send a message to the other board to lock or unlock its drum.
John,
I have gone through a number of the examples that were in Bill's "Introduction to ESP32 - Getting Started" video. Without me reading more info on the programming basics, I'm still struggling with what all the code means. In time, I think it will come to me, but I see a lot more reading on my part for it to happen.
I will install the ESP-NOW library and run your test code above and report back.
I might mark this topic as SOLVED and continue the project discussions back in my original topic.
Cheers,
Ian
Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice
Just to let you know I am still working on a readable working example which you can test on your hardware.
Unless someone has already given you a working solution which you have been able to implement?
John,
The only other solution is Tim's that I haven't gone any further with.
When you have done that you need to know their MAC address. You can find that out by running this program on each board. I found the one on Bill's tutorial didn't work anymore but this one does.
I had already obtained the MAC address, maybe by accident, as I saw it reported in the Output screen when I uploaded the BLINK sketch.
I just confirmed the address was correct by running the program you posted.
I hope to be able to load your ESP-NOW test program either today or over the weekend to test.
You can test if the two boards are communicating by loading the program below on both boards but with the MAC addresses of the other board.
I presume I just need to swap which one is commented out.
Cheers,
Ian
Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice
So you have the MAC address for both boards using the above get MAC address program? You have run it on each board and noted each board's MAC address. After uploading the get MAC address program you need to have the Serial Monitor running and press the reset button to get the address displayed.
Then you can load the demo code above on both boards edited with the other board's MAC address and another message.
I named one board the red board (has a red LED) and the other board the green board (has a green LED) so not to confuse which is which. The MAC address is like the phone number one board has to ring to connect to the other board so each board has the other board's MAC address.
I also edited the code to send a different message for each board.
strcpy(outgoing.msg, "Hello I am the RED board");
strcpy(outgoing.msg, "Hello I am the GREEN board");
Apart from that the sketch for both boards is the same.
If the boards are now communicating we are ready to go ...
I have to go now, back later and we can edit the code and hook up the hardware for testing.
Let me know when you have successfully installed the ESP-NOW library.
John,
I seem to be having problems installing the correct ESP-NOW library into the Arduino IDE.
Which is the correct one I should be looking for when searching?
When I search for "esp-now", the only one that is close to that is called "ESP_NOW_Network". I cannot find one that's just called "ESP-NOW".
After a Google search and looking on Arduino.cc, there is reference to the "SimpleEspNowConnection" library. Will this one work?
Cheers,
Ian
Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice
Does the sketch with
#include <esp_now.h>
#include <WiFi.h>
above actually compile when you click the tick icon for Verify at the top/left of Arduino IDE?
If so then the ESP NOW is installed?
If you can compile anything for the esp32 then you have the ESP32 add-on installed in your Arduino IDE and perhaps esp_now.h is part of that installation? I honestly can't remember what steps I took to get esp32 and ESP-NOW working I just blindly followed instructions.
I see that ESP NOW is a protocol probably in the esp_now.h file and not a library.
Remember this esp32 and ESP NOW is new to me because up to now I have just been using the old UNO and MEGA boards and not bothered with wifi stuff or even needed it.
@robotbuilder @imillard Here is Bill's esp_now tutorial. Yes, it's built in, no libraries needed.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Thanks. As I thought in my last post it must be part of the package as I don't remember installing it I just imagined I must have done so and forgotten. If the above code compiles it must be there. It was never explicitly stated in any articles about ESP NOW that it was included in the installation for programming the esp32 with the Arduino IDE.
@robotbuilder It sort of is, in that it is an extension of WiFi and it is an Espressif invention, but your points and concerns are good procedure. I went and checked the library manager before I wrote the previous post, and I looked at what Bill said. ONLY after doing that did it remind me that it is built in. Just now I did a search on the esp32 libraries and here is the result. The various .h files are for different esp32 boards like S2, S3, C6 and so on.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.