i have a Genuino101 board and HM-11 module. Im trying to set the parameters of the module like name, etc. So i started with a simple code but it doesnt work. As we can see, my serial monitor is supposed to show "SETUP 1" and "SETUP 2". But this is what my serial monitor shows.
SETUP 1
It did not show or print "SETUP 2". So im guessing the problem is in between. I tried to comment out mySerial.begin(4800); and saw that this.
SETUP 1SETUP 2LOOP
LOOP
LOOP
LOOP
LOOP
LOOP
it works as it should except that i removed the mySerial.begin(4800).
Is this a softwareSerial problem? I also tried changing baud to 9600 but still problem arises. Looks like mySerial.begin(4800) pauses the arduino. Please help.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);
void setup(){
Serial.begin(9600);
delay(2000);
Serial.print("SETUP 1");
mySerial.begin(4800);
delay(2000);
Serial.print("SETUP 2");
mySerial.print("AT+NAMEMASTER0000");
}
void loop(){
delay(1000);
Serial.println("LOOP");
}
EDIT:
The problem was the code paused halfway because of an error in initialization of software serial caused by RX/TX pins being interchanged. The problem was fixed automatically after swapping RX/TX pins.
Related
Good morning everyone.
I am trying to establish serial communication between an arduino mega and an esp32, in both I am using hardware serials.
In the arduino the uart3 in the esp the uart2. I have checked the pin connections several times.
I also adapted the arduino's tx signal to the esp32 with a level shifter.
Essentially I need to send a string to the esp32.
The code of the arduino is as follows:
String InvioDatiESP() {
String da_passare = ("hello!!!");
return(da_passare);
}
void setup() {
Serial.begin(9600);
Serial3.begin(115200);
}
void loop() {
Serial3.println(InvioDatiESP());
Serial.println(InvioDatiESP());
delay(1000);
}
I create the string in a function since it is a reduced version of the actual code in which the string is to be composed.
The code of Esp32 is as follows:
#define RXp2 16
#define TXp2 17
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, RXp2, TXp2);
}
void loop() {
Serial.println(Serial2.readString());
}
I correctly set the boudrate in both serial ports on the IDE to verify communication.
The thing I notice that makes me doubt that the problem is related only to the ESP32 reading the string is that in the serial port of the ESP32 in the IDE while the program is running, blank lines are printed on the screen exactly every 1000ms, as if the data is received but not interpreted correctly.
How could I solve this in your opinion?
Thanks in advance for the answers!
SOLVED, the lever shifter was disturbing the signal too much, seen with the oscilloscope, I used a resistive divider and everything works perfectly, thank you all the same!
EDIT: Can you try to lower the boudrate? Check to see if with a lower one it will start decoding properly.
Your problem is not with the code, it's with the hardware. The arduino Mega2560 is using 5V logic level and ESP32 is using 3.3V.
You need to do some level shifting to be able to communicate.
You can take a look at this article to learn more about it.
Hope it helps.
I am completely new to this and willing to do a simple task using stm32f103c8t6 board, which is "led blink".
Using ArduinoIDE and a simple circuit as shown in the picture, everything goes fine on port PC13. but as soon as I try other ports, it doesn't work.
My aim is to be able to toggle the led status using ports PA0 to PA5.
Here is my code:
void setup() {
// initialize the digital pin as an output.
pinMode(PC13, OUTPUT);
}
void loop() {
digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
I change PC13 to PA0, and rewire the board, but no luck :(
How can I solve this issue.
Any kind of help is highly appreciated.
You are using an external LED right (it's a bit difficult to tell for sure in your photo)? The "blue pill"'s internal LED is tied to PC13 only. If you are using an external LED and the program with PC13 works, then there should not be any issue with PA0 to PA5. The only thing I can think of currently is that somehow your program is not being flashed correctly so it's still running the old code.
To test this theory, start with the working PC13 program and then modify the delay time to 2 secs or whatever. Then you can be sure that the new program is downloaded correctly.
Sorry for the stupid question. My problem was that I had a broken wire,and when I changed it, everything was working fine.
I am new to electronics, and trying to get my 1602 LCD to work with an I2C adapter.
I got my backlight to work, but I can't get text to show.
This is my current code:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(5, 0);
lcd.print("HELLO");
}
void loop() {
lcd.backlight();
delay(2000);
lcd.noBacklight();
delay(2000);
}
I checked for the I2C address with the scanner and it is 0x27.
I Googled a bit and came past this post where someone posted this:
Simple test
Apply +5v / GND to LCD - display - and than apply background LED power ( sometime marked A/K) to the LCD module.
No other connections ( data etc.) are necessary for this power up test.
You should be able to discern ALL chatterers fields, but connecting contrast pot will make it easier.
It MAY not be totally visible but the module will initialize ( internally) on power up and ALL characters fields should show.
Of course by now you know you need basically three "power" connections to the LCD - LCD itself, contrast and backlight.
Sure looks as the main LCD power is missing - hence no intelligent data can be processed / displayed.
I did this test aswell and came to these results:
When providing 5V to the backlight, it shows up bright.
When providing 5V to both the backlight and the LCD itself the backlight gets darker but nothing else shows up.
I then accidentally put the I2C adapter upside down, but that did give me the text blocks.
How could I get the text to show? What am I currently doing wrong?
Minor point, have you tried trimming the pot? I suspect that this sets the contrast, and I forgot this and I had a blank display.
Yours Simon M.
Your I2C Adapter turns serial data into parallel output to the LCD pins.
Are you sure this is done to the pins you expect ?
Especially if you mix any I2C adapter to any 16 pin LCD module, you should check which signals you put where ...
If required, there are LiquidCrystal_I2C constructors where you can specify the LCD pins, if the default won't fit.
i want to code a simple Hello World code in Arduino to show it on its system monitor, my code is:
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Hello world!"); // prints hello with ending line break
}
void loop() // run over and over again
{
// do nothing!
}
but when i run this code, i get This Image characters on the system monitor.Also, i change the Serial.begin() from 9600 to other things but it does not work!How can i fix the problem?
Check your BAUD Rate on the Serial Monitor. Make sure its 9600, as you told it should be in your code:
Serial.begin(9600);
In the bottom of the Serial Monitor, there is a drop down to select the baud rate:
Your linked < This Image > shows a lot of garbage.
Wrong baud rate would rarely produce that much (mow many resets are seen there?
What type of arduino do you use?
Can you assure SerialMonitor in the Arduino IDE is connected to Serial on your Arduino?
I am using an Arduino Mega with a 16x2 LCD. When I start the Arduino the LCD flashes white and sometimes random lines will show up and gradually fade out. The backlight is on, however, so the LCD is not inverted. At first I thought the Arduino was not getting enough power because I am using a Raspberry Pi to program it, but plugging in a 6V battery pack did not change the result. I tried plugging in a different 16x2 LCD to check if the one I was using is broken, but again, the result was the same. I have triple-checked my connections, adjusted the potentiometer, and fiddled around with where the LCD was connected on the breadboard in case some of the pins were broken, but to no avail.
Does the LCD have a problem with Arduino Mega boards? Or am I just unfortunate enough to have two broken LCDs?
Code:
#include <LiquidCrystal.h>
#define led_pin 22
#define buzzer_pin 7
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(buzzer_pin, OUTPUT);
lcd.begin(16,2);
digitalWrite(led_pin, HIGH);
tone(buzzer_pin, 1000, 500);
delay(500);
digitalWrite(led_pin, LOW);
lcd.print("LCD Test");
}
void loop() {
}
EDIT
I moved the LCD and wiring back to the other side of the breadboard and it did not change the output. I'm starting the think that the LCDs are just simply broken because the LCDs will randomly flash and fade unevenly. I found that these LCDs can be easily fried by incorrectly adjusting the potentiometer.
Make sure that you solder headers to the lcd, then press the headers into your breadboard and connect to arduino with jumper wires. Just resting the LCD on the headers without solder or jabbing the lcd pin holes with jumper wires don't make reliable connections. You WILL see random stuff
Make sure you connect the LCD correctly. If you did, you wouldn't have got any problems. Post a picture.
Make sure the pins you used in the code match pins you connected to the LCD.
Best way to get arduino help is on arduino forum.
Specifically which LCD are you using?
Do you have datasheets for the exact LCD you are using so you can confirm you have the correct wiring and supply voltages?
If you still have no luck, you may want to try a LCD module that has a serial, i2c, or spi interface.
They are much easier to use than HD44780 parallel modules (im assuming this is what you have).
An example source of such modules is https://www.crystalfontz.com/c/character-lcd-displays/interface/24