No output from ESP32S PlatformIO - arduino

I am following to the official tutorial and trying to get my ESP32S give some output.
Official tutorial
I can do everything but I am not getting any output. My OS is Ubuntu 22.04 LTS, the code I try to launch:
#include <Arduino.h>
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Hello world!");
delay(1000);
}
This is what I got at the monitor (NO FRACKING "HELLO WORLD!" MESSAGE).
I have tried to execute blink program with no success either!
The Program:
#include <Arduino.h>
#define LED 2
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED, HIGH);
Serial.println("LED is on");
delay(1000);
digitalWrite(LED, LOW);
Serial.println("LED is off");
delay(1000);
}
Output for both programs with empty log files. Nothing in them!
And LED doesn't blink.
This is my platformio.ini file:
[env:wemos_d1_mini32]
platform = espressif32
board = wemos_d1_mini32
framework = arduino
lib_deps = kitesurfer1404/WS2812FX#^1.4.1
monitor_speed = 9600
monitor_filters = esp32_exception_decoder, default, log2file, colorize
debug_tool = olimex-arm-usb-ocd-h
Device is connected, I checked it.
I mean I have no Idea why this is not working!

In platformio.ini file add 2 lines and it will work:
[env:wemos_d1_mini32]
platform = espressif32
board = wemos_d1_mini32
framework = arduino
lib_deps = kitesurfer1404/WS2812FX#^1.4.1
monitor_speed = 9600
monitor_filters = esp32_exception_decoder, default, log2file, colorize
debug_tool = olimex-arm-usb-ocd-h
monitor_dtr = 0
monitor_rts = 0
Something with these dtr and rts pins are not ok so you just disable them and the software will be working.

debug_tool = olimex-arm-usb-ocd-h
Looking at this line at platformio.ini, I am assuming that you have a debugger connected. In that case, is platformIO identifying the right serial port?
Identify your Serial port of the ESP32 and add this line with your COM port number like the following to your platformio.ini -
upload_port = COM3

Related

Sending data from Arduino UNO to NodeMCU over UART and processing received data on NodeMCU

I'm trying to send data from Arduino UNO to NodeMCU via UART.
What I want to do is that when Arduino UNO sends "on" String to the NodeMCU, NodeMCU lights up its builtin LED, when "off" - it turns off.
I send data from Arduino UNO via standard Serial.println (). On the NodeMCU I use the SoftwareSerial library. I assigned rx and tx to pins D7 and D8 accordingly. Serial ports on Arduino(standard) and NodeMCU(SoftwareSerial) are set at 9600 baud rate.
Standard Serial port (USB) of NodeMCU is set to 115200.
I send the string that I receive from the Arduino to the standard serial port of the node (connected to usb)
The question is:
On the standard port of NodeMCU, which I view through the Arduino IDE, messages coming from the arduino are displayed, and displayed correctly (those that were sent), but the NodeMCU does not want to accept them in conditional statements and light up my LED. Why?
At the same time, when I remap the virtual UART to its original pins (connected to USB, GPIO3 and GPIO1, and send the same messages via usb through the COM port view in the Arduino IDE, the LED turns on and off as I programmed it.
Do you have any ideas why this is happening?
By the way, I do not lower voltage coming from Arduino RX and TX pins from 5V to 3.3V, but since messages are recived coorectly, I don't think that this is causing a problem.
Here's my code:
Arduino:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("on");
delay(1000);
Serial.println("off");
delay(1000);
}
NodeMCU:
#include <SoftwareSerial.h>
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
Serial.println(str);
if(str == "on"){
digitalWrite(D4, HIGH);
}
if(str=="off"){
digitalWrite(D4, LOW);
}
}
Screenshot of COM4:
Screenshot of COM4:
UPD: I tried using sending 1 or 0 as int value via Serial.write() and s.read() and it works, maybe the prolem is in String type somehow
You Use İt Maybe Work
#include <SoftwareSerial.h>
String text = "";
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
text = str
Serial.println(text);
if(text == "on"){
digitalWrite(D4, HIGH);
}
if(text =="off"){
digitalWrite(D4, LOW);
}
}

Esp8266-01 Arduino Uno. Status to Firebase

I am having problems connecting my Esp8266-01 to my Arduino Uno. I want to be able to connect it so that it can send the below code for a microswitch to Firebase (+LLC). I am not getting any response from AT commands in the serial monitor and have tried both NL & CR as well as changing from 9600 to 115200 baud rate. My esp only displays a red led and not the blue one.
int pressSwitch = 0;
void setup()
// put your setup code here, to run once:
{
Serial.begin(9600);
}
void loop()
// put your main code here, to run repeatedly:
{
pinMode(LEVER_SWITCH_PIN,INPUT);
pressSwitch = digitalRead(LEVER_SWITCH_PIN);
if(pressSwitch == HIGH)
{
Serial.println("CLOSED");
delay(1000);
}
if(pressSwitch == LOW)
{
Serial.println("OPEN");
delay(1000);
}
}```

NFC tag v1.0 & arduino UNO

My teacher just gave me a NFC tag v1.0 for a project. I have to use my phone to unlock a door.
I searched on internet and I just found this code:
#include "NfcTag.h"
#include <Wire.h>
NfcTag nfcTag;
int led = 5;
bool flag = false;
bool preFlag = false;
void setup(){
Serial.begin(9600);
pinMode(led,OUTPUT);
nfcTag.init();
}
void loop(){
flag = nfcTag.readByte(EEPROM_I2C_LENGTH-1) == 0xff?true:false;
if(flag != preFlag){
Serial.println("get remote NFC control signal!");
if(flag == true){
Serial.println("led will light up!");
digitalWrite(led,HIGH);
}else{
Serial.println("led will turn dark!");
digitalWrite(led,LOW);
}
preFlag = flag;
}
delay(5*1000);
}
This come from their wiki: http://wiki.seeed.cc/Grove-NFC_Tag/
I can connect with the phone and use it to change blocks. The problem is that when I try it, the LED just doesn't work at all. I tried the LED and he is working, I also tried the Digital pin on the Arduino UNO with the LED and it works as well. Also, the monitor doesn't show any off those printLn.
I used this way to connect them:
SCL - RX
SDA - TX
GND - GND
5V - VCC
I also used a code to debug, but no matter what address I use to readByte, I will always get the number 127 even after using the phone to change it with the app.
#include "NfcTag.h"
#include <Wire.h>
NfcTag nfcTag;
bool flag = false;
bool preFlag = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("starting sequence");
nfcTag.init();
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("checking for nfc");
//flag = nfcTag.readByte(EEPROM_I2C_LENGTH-1) == 0xff?true:false;
//Serial1.println(flag);
Serial.println(nfcTag.getICNumber());
Serial.println(nfcTag.getAFI());
Serial.println(nfcTag.getRFU());
Serial.println(nfcTag.getMemoryVolume());
Serial.println("result:");
Serial.println(nfcTag.readByte(EEPROM_I2C_LENGTH-1)); //I tried changeing manualy the value, but the output still 127.
delay(2000);
}
Output:
checking for nfc
127
127
32639
8355711
result:
127
If I could put the LED working, I have already a transistor with a power converter on the exit of the pin5, so the door can be unlocked.
By the way, I don't know why sometimes the NFC doesn't work and after some tries it start working again.
Any help will be appreciate :) Thanks.
The correct connection for the I2C pins is:
SCL - PC5 (Analog A5)
SDA - PC4 (Analog A4)
This part supports Uart communications as you wired it. The link you provided for the part you are using only support I2C and will not work as you wired it.

ESP8266 connected to my Arduino Uno

I have the ESP8266 connected to my Arduino Uno. With a blank sketch I can use Serial Monitor to connect it to my wifi network using these commands
AT+IPR=9600
AT+CWMODE=1
AT+CWJAP="SSID_HERE",""
It get's an ip and everything. But now I want my sketch to just do this using this code
#include <SoftwareSerial.h>
#define SSID "SSID_HERE"
void setup(){
Serial.begin(9600);
Serial.setTimeout(5000);
delay(1000);
}
boolean connectWiFi()
{
// connect
Serial.println("AT+CWMODE=1");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"");
delay(2000);
if(Serial.find("OK"))
{
Serial.println("AT+CIFSR");
Serial.flush();
delay(1000);
return true;
}
else
{
// Can not connect to the WiFi.
return false;
}
}
But it doesn't work.. The Serial.println shows up in the Serial Monitor, but the ESP8266 doesn't seem to respond. What am I missing?
AT -commands ends with carriage return, so you need to add '\r' to every command you print.
In your code lines looks like:
Serial.println("AT+CWMODE=1\r");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"\r");
Serial.println("AT+CIFSR\r");
Reference: https://en.wikibooks.org/wiki/Serial_Programming/Modems_and_AT_Commands/Special_Commands_and_Character_Sequences
The problem here is that you are trying to use pins 0 & 1 for the serial comms, well its part of the problem.. Because the arduino uses serial as well, it for me is only really good to use pins 0 & 1 for serial when i've grounded the reset pin on the arduino. This turns the arduino into a dummy device.
You can use something like software serial and two different pins instead, this way you will not interfere with the hardware serial of the arduino.
Also just to note, the below example will barely work.. For some it will for others it wont.. The problem here is that software serial does not really work / run at 115200..
You can change baud rate via AT+UART_DEF=19200,8,1,0,0 which will also disable flow control, then use software serial with a different speed mySerial.begin(19200)
Using Serial.println("TEXT") will send the line returns for you, so no need to add them unless you use Serial.print("TEXT\r\n")
DO NOT USE: AT+IPR= as this will brick it and require a reflash
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
pinMode(11, INPUT);
pinMode(10, OUTPUT);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("ARDUINO: Starting");
mySerial.begin(115200);
Serial.println("ARDUINO: Sending AT Command");
mySerial.println("AT");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

C code equivalent to serial monitor commands like Serial.begin,serial.flush,serial.read,serial.available,etc

Hi I am trying to learn coding microcontrollers on my own. I am trying to code my arduino board (ATMEGA8A-PU) in embedded C using the arduino ide itself. I have blinked my LED so far. Now I am trying to control its state using the serial monitor(sending "on" lights it up and "off" switches it off). But I don't know the C commands to do it.I successfully did it using the arduino Serial commands.
int led = 13; // Pin 13
void setup()
{
pinMode(led, OUTPUT); // Set pin 13 as digital out
// Start up serial connection
Serial.begin(9600); // baud rate
Serial.flush();
}
void loop()
{
String input = "";
// Read any serial input
while (Serial.available() > 0)
{
input += (char) Serial.read(); // Read in one char at a time
delay(5); // Delay for 5 ms so the next char has time to be received
}
if (input == "on")
{
digitalWrite(led, HIGH); // on
}
else if (input == "off")
{
digitalWrite(led, LOW); // off
}
}
So please help.
You are using Serial class and functions like begin(), print() etc from the Serial class which is C++ language. These are the C++ commands native to the Arduino development environment. So anyway you ar using C/C++ commands here.

Resources