My esp32 print weird characters but I do anything - c++

I only want to print simple text but it print unilimited weird character and never stop, (when I remove Serial.print() it continues to print weird characters).
This is the weird text that loop
-*⸮ql⸮7⸮$⸮
*!8P⸮⸮⸮V⸮)3 ⸮;⸮ 1⸮zY⸮b⸮ڔ!⸮⸮$q⸮,*⸮ı⸮N
⸮a!u⸮ 1⸮zY⸮b⸮⸮⸮⸮⸮⸮!⸮ 1⸮zY⸮W(⸮⸮⸮xI⸮
,*-⸮l⸮N
⸮a!u⸮,*⸮⸮⸮nbb⸮H⸮⸮⸮⸮,*⸮⸮⸮nbb⸮H$⸮
1⸮zY⸮b⸮ڔ!X⸮⸮⸮⸮,*⸮⸮⸮nbb⸮H$⸮
*!8Pt⸮
My code :
void setup() {
}
void loop() {
}
I hope you can help me, thanks :)
UPDATE
I completely removed Serial.begin(9600) and Serial.print() and I still have the problem O_o

If you are using arduino IDE ( you probably are ) you can try changing the baud rates. That's what happened to me in arduino some time ago

I just changed the Flash memory speed to 40MHz instead of 80MHz

You need to make sure that the baud rate in the code and baud rate of the serial monitor are the same.
Example:
if your code has : Serial.begin(115200);
then change the baud rate of serial monitor to 115200, this can be done by accessing the baud as shown in the pictureimage below

Related

How to communicate with sim800c using Raspberry pi 3 in c++

My end goal is to try and send some simple data that's stored on my Raspberry pi 3 to an external server/website using a sim800c from a c++ program. I believe the easiest way to do this is to issue "AT commands" to the sim/modem however I'm struggling to do this. I can't figure out how I'm actually suppose to issue AT commands or how I can check if they're working. For testing purposes I've written some code which should send a text message to a phone number once I've gotten this working it should be fairly straight forward to figure out the AT commands to communicate with a server.
Below is an image of how I've wired everything up which I'm fairly confident is correct.
https://i.imgur.com/zysmNXE.jpg
Below is the basic c++ code that I've written using various guides, it compiles and runs in terminal however I don't get any response from the AT commands and more importantly as far as I can tell their not actually being executed. I've tried changing the fake number to my personal one but it didn't make a difference.
#include <stdio.h>
#include <string.h>
#include <wiringPi.h>
#include <wiringSerial.h>
int main ()
{
int connection;
printf("Opening connection \n");
connection = serialOpen("/dev/ttyAMA0", 9600);
delay(1000);
printf("Connection: %d\n", connection);
printf("\n");
//Set gsm to text mode
serialPuts(connection,"AT+CMGF \r\n");
delay(1000);
//Number that the message should be sent to
serialPuts(connection,"AT+CMGS=\"12345678900\"\r\n");
delay(1000);
//The message
serialPuts(connection,"Hello World");
delay(1000);
//Print ctrl+x
serialPuts(connection,"\x1A");
delay(1000);
printf("Done \n");
return 0 ;
}
As far as I can tell there are 3 likely reasons why it's not working;
A possible config/settings issue with the pi
I've wired it up incorrectly
The sim/module isn't working
I'm just not sure how to go about testing/finding what is causing the issue. If I could get my code to output the response of the AT commands after doing "serialPuts" that might help me figure out whats going on but I haven't made much luck doing that. Alternatively If anyone has an idea why the commands don't appear to be working or can provide me some ways to debug/test them that would be great.
The issue turned out just to be a simple wiring mistake.
I had wired the txd pin of the sim module to the txd pin on the raspberry pie as I was under the impression you just needed to match the pins however I didn't think/realize that the txd pin needed to go to the rxd pin instead. Changing these around allowed me to see the commands & responses being returned from the module.
To actually get the gprs working I also needed to temporarily set the pwr pin to low then high.

arduino fio v3, GPS NMEA reading error, crazy output

Hello I have a GP20U7 GPS that transmits in NMEA. I am currently reading in that character by character. But it seems to give me two somewhat reasonable NMEA formatted strings and then just goes silly, any help?
I have all my code attached below. I am also outside, so i shouldn't have any connection errors. I also have waited over two minutes for a connection and it still outputs the same mess.
also below is what the character output looks like in my serial monitor.
$GPRMC,233720.00,V,,,,,,,251016,,,N*7B
$GPVTG,,,,-‰‰‰ÉJi‚j
$GP$4$G$G6$G$GP$G
$G$GG$G$G$$G$GP$G0$G$A*$G$G,$G0$T$G7$1$G,$R$G,$GÒ,$G
$6$G5$1$G,$1$G7$7$G,$G$G,$G$G,$GA$1$G3$
#include <XBee.h>
#include <Wire.h>
#include <SparkFunMPL3115A2.h>
#include <SPI.h>
#include <SparkFunLSM9DS1.h>
#include <SoftwareSerial.h> //XBEE Comms
#include <SD.h>
SoftwareSerial XBee(0, 1); // RX, TX (0 and 1 are the TX/RX pins
SoftwareSerial gps(9, 10);
MPL3115A2 altimeter;
LSM9DS1 accelerometer;
#define LSM9DS1_M 0x1E //I2C addresses of the LSM9DS1
#define LSM9DS1_AG 0x6B
#define PRINT_CALCULATED
const int chipSelect = 10;
void setup()
{
accelerometer.settings.device.commInterface = IMU_MODE_I2C;
accelerometer.settings.device.mAddress = LSM9DS1_M;
accelerometer.settings.device.agAddress = LSM9DS1_AG;
gps.begin(9600);
XBee.begin(9600);
accelerometer.begin();
altimeter.begin();
altimeter.setModeAltimeter();
altimeter.setOversampleRate(7);
altimeter.enableEventFlags();
XBee.println("start");
}
void loop()
{
File dataFile = SD.open("datalog.txt", FILE_WRITE);
char rc;
if(gps.available())
{
rc = gps.read();
Serial.print(rc);
}
else
{
Serial.println("NOT Available");
}
float altitude = altimeter.readAltitudeFt();
float temperature = altimeter.readTempF();
XBee.println("Altitude");
XBee.println(altitude);
XBee.println("Temperature");
XBee.println(temperature);
XBee.println("Next");
delay(100);
dataFile.close();
}
The data looks like it should be correct, but displays weird
characters.
After removing the delay this is what my output looks like:
$GPRMC,183714.00,V,,,,,,,,,,N*75 $GPVTG,,,,,,,,,N*30
$GPGGA,1ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$ÿGÿPÿRÿMÿCÿ,ÿ1ÿ8ÿ3ÿ7ÿ1ÿ8ÿ.ÿ00ÿÿ,Vÿÿ,,ÿÿ,,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿNÿÿ7ÿ9ÿ
$GÿÿPVÿÿTGÿÿ,,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿNÿÿ3ÿ0ÿ
$ÿÿGPÿÿGGÿÿA,ÿ1ÿ8ÿ3ÿ7ÿ1ÿ8ÿ.ÿ0ÿ0ÿ,,ÿÿ,,ÿ,ÿ0ÿ,ÿ0ÿ0ÿ,ÿ9ÿ9ÿ.ÿ9ÿ9ÿ,ÿ,ÿ,
$ÿGÿPÿGÿSÿAÿ,ÿAÿ,ÿ1ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,,ÿ9ÿ9ÿ.ÿ9ÿ9ÿ,ÿ9ÿ9ÿ.ÿ9ÿ9ÿ,ÿ
$ÿGÿPÿGÿLÿLÿ,ÿ,ÿ,ÿ,ÿ,1ÿÿ83ÿÿ71ÿÿ8.ÿ0ÿ0ÿ,ÿVÿ,ÿNÿÿ4ÿEÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$ÿGÿPÿRÿMÿCÿ,ÿ1ÿ8ÿ3ÿ7ÿ1ÿ9ÿ.ÿ0ÿ0,ÿVÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿNÿÿ78ÿÿ
$GÿPÿVÿTÿGÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,Nÿÿ*3ÿÿ0
$ÿGÿPÿGÿGÿAÿ,ÿ1ÿ8ÿ3ÿ7ÿ1ÿ9ÿ.0ÿÿ0,ÿÿ,,ÿÿ,,ÿ0ÿ,ÿ0ÿ0ÿ,ÿ9ÿ9ÿ.ÿ9ÿ9ÿ,ÿ,ÿ,$ÿGÿPÿGÿSÿAÿ,ÿAÿ,ÿ1ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,,,ÿ,ÿ,ÿ,ÿ,ÿ9ÿ9ÿ.ÿ9ÿ9ÿ,ÿ9ÿ9.ÿÿ99ÿÿ,9ÿ
$GÿÿPGÿÿLLÿ,ÿ,ÿ,ÿ,ÿ,ÿ1ÿ8ÿ3ÿ7ÿ1ÿ9ÿ.ÿ0ÿ0ÿ,Vÿÿ,Nÿÿ*4ÿFÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$ÿÿGPÿÿRMÿCÿ,ÿ1ÿ8ÿ3ÿ7ÿ2ÿ0ÿ.ÿ0ÿ0ÿ,ÿVÿ,ÿ,,ÿÿ,,ÿÿ,,ÿ,ÿ,ÿ,ÿNÿÿ7ÿ2ÿ
$ÿGÿPÿVÿTÿGÿ,ÿ,,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿNÿÿ3ÿ0ÿ
$ÿGÿPÿGÿGÿAÿ,ÿ1ÿ8ÿ37ÿÿ20ÿ.ÿ0ÿ0ÿ,ÿ,ÿ,ÿ,ÿ,ÿ0ÿ,ÿ0ÿ0ÿ,ÿ9ÿ9ÿ.ÿ99ÿÿ,,ÿÿ,$GÿÿPGÿÿSAÿÿ,Aÿ,ÿ1ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,ÿ,,ÿÿ,9ÿÿ9.ÿÿ99ÿ,ÿ9ÿ9ÿ.ÿ9ÿ9ÿ,ÿ9
$ÿÿGPÿGÿLÿLÿ,ÿ,ÿ,ÿ,ÿ,ÿ1ÿ8ÿ3ÿ7ÿ2ÿ0ÿ.ÿ0ÿ0ÿ,Vÿ,ÿNÿ*ÿ4ÿ5ÿ
As we discussed on the Arduino forum, remove the delay(100).
Update 1:
The next problem is that you are printing 15 characters every time you don't receive a GPS character. So... you're printing that message a lot. And then you send a new XBee message, regardless of whether you received one character. Aaaand you're opening and closing the SD file on every iteration of loop. That's a lot. All of those things keep loop from reading the GPS characters. Again, those characters stack up in the input buffer until its full and they start getting dropped.
I would suggest looking at the examples for my GPS library, NeoGPS. They are all structured around the GPS update interval. The Installation instructions suggest a few sketches to try. The Troubleshooting section may help you understand the interaction between the GPS interval and printing (too much!).
It's important to understand that the GPS devices sends several hundred characters each second (i.e., "interval"). NeoGPS parses those characters into a fix structure, and makes it available, once per second. After a fix becomes available, the GPS device is "quiet" until the next interval begins (maybe in 0.4s). That's the perfect time to do something else, like send an XBee message.
Also, SoftwareSerial is very inefficient, so it could also be causing problems. AltSoftSerial is a better choice if you can put the GPS on pins 8 & 9.
BTW, the lower-case y with umlaut is character 255. I suspect you called gps.read() without first testing if (gps.available()). When no characters available, read() will return -1, which is printed as a 255. You probably modified something that we can't see.
The Arduino forum would be a better place for this kind of "conversation". (I'm replying to your comment below... :P ) It will take several iterations before your sketch works. When it does, we can come back here with a summary answer. Here's your post if you don't mind working over there.

Arduino not taking multiple commands

I'm trying to get the basics done with my Arduino, and thus I'm starting off small.
That said, I want the Arduino to listen for simple, multiple commands being sent from my Raspberry Pi (I'm emulating this through the serial monitor now, however)
This is the code I'm working with:
#include "SoftwareSerial.h"
void setup()
{
Serial.begin(9600);
delay(100);
}
void loop() {
if (Serial.find("test1")) {
delay(100);
Serial.println("TEST1 command received");
}
if (Serial.find("test2")) {
delay(100);
Serial.println("TEST2 command received");
}
}
}
Sadly, only the test1 command triggers a serial print response, test2 no. Can anyone here help point me in the right direction?
Thank you!
From reading the documentation, I don't think you can use the find() function like that.
Consider what happens if test2 is input, when the find("test1") call is running. It will probably consume all characters up to and including the 2, and then return false, at which point those characters are lost.
I think you should design an actual protocol, with some delimiter between commands, and read/parse those.

Arduino servo not responding to button press

I'm pretty sure there is a stupid error here but I'm afraid I can't for the life of me work it out!
Simple test program that gets the error:
#include <Servo.h>
Servo myservo;
int testPIN = 13;
int inputPIN = 5;
void setup()
{
myservo.attach(8);
pinMode(testPIN, OUTPUT);
pinMode(inputPIN, INPUT);
}
void loop()
{
if (digitalRead(inputPIN) == HIGH)
{
digitalWrite(testPIN, HIGH);
myservo.write(90);
}
else
{
digitalWrite(testPIN, LOW);
myservo.write(0);
}
}
The arduino sweep example (http://arduino.cc/en/Tutorial/Sweep) works, so I'm fairly confident the electronics works.
The testPIN also goes on and off as expected so the if statement is working as expected.
Any ideas/suggestions welcome!
EDIT - Sorry the error is that the servo doesn't move at all
EDIT 2 - Something a bit odd is going on here. If I copy/paste the sweep loop into the if clause, the servo reacts as expected (ie input = high makes the servo run a sweep loop, which it doesn't break out of until it reaches the end of, as expected). My immediate thought was delays were needed, but they seem to make no difference no matter how long they are or where they are added in the if/else clauses.
I don't know which arduino board you have, but on the arduino uno, i'm pretty sure that the pin 8 is not a PWM output. And you can not run a servo on a non-PWM output.
See this image of the Uno board, and notice that there is no tilde (the indication that a port supports PWM) on pin 8:
Have you tried using SoftwareServo.h instead? This example looks like what you are trying to accomplish: http://playground.arduino.cc/ComponentLib/servo
The sweep program that you're linking to is using pin 9, which is a PWM on an uno. Your code is using pin 8, which is NOT a PWM output. Switch your servo over to pin 9 and change the attach in your code to pin 9 and, assuming that this is your only issue, your code should work.
As suggested in the comments, I've just written a function that moves the servo slowly. Not an elegant solution but servo response time isn't issue so it does the trick.
Thanks for all the help and suggestions, and to #praks411 for the wrapper function work around.

Cannot connect Wifly to Arduino

I am just an Arduino beginner. I bought an Arduino Uno and a Wifly shield yesterday and I am not able to run the Wifly_Test example program come with WiFlySerial library.
When I look at Serial Monitor, I only saw 2 lines are printed out
1.Starting WiFly Tester.
2.Free memory:XXXX
How can I know that the Wifly Sheild that I bought is not faulty?
I soldered the heard ping to Wifly Shield and stacked it to Aurduino Uno and I can see the LEDs blinking on the Wifly Shield.
Do I need to reset the Wifly Sheild? How do I reset it?
Please point me to the most simple example on how to connect to the router.
I have also bought the shield and had trouble to start with.
If you have soldered the pins to the shield that should be fine but make sure you check they all have a connection and that they don't have solder running down the legs of the pins as this causes the shield to be temperamental.
Run the code below which is from the WiFly library (alpha 2 version) that can be found here:
http://forum.sparkfun.com/viewtopic.php?f=32&t=25216&start=30
Once you see that the shield has connected it will ask for an input, type $$$ and press enter... you have now entered the command line and CMD will be displayed.
If you do not know your network settings type scan and this will display them.
Then set your authentication by typing set wlan auth 3 (Mixed WPA1 & WPA2-PSK) or set wlan auth 4 (WPA2-PSK) this depends on the type of authentication you ise so pick the write one for your network.
Then type set wlan phrase YourPharsePhrase (Change YourPharsePhrase to whatever your WPA key is)
Then type join YourSSIDName (Change YourSSIDName to whatever your network name is)
You see something like this:
join YourSSIDName
Auto-Assoc YourSSIDName chan=1 mode=MIXED SCAN OK
Joining YourSSIDName now..
<2.15> Associated!
DHCP: Start
DHCP in 1234ms, lease=86400s
IF=UP
DHCP=ON
IP=10.0.0.116:2000
NM=255.255.255.0
GW=10.0.0.1
Listen on 2000
you are now connected to your network.
Hopefully this will get you up and running.
N.B. REMEMBER TO CAREFULLY CHECK YOUR PINS! I had great trouble with mine because only a small amount of solder is needed but enough to get a good connection, the balance of this was minute but enough that it wouldn't work. I used a magnifying to check mine in the end.
#include "WiFly.h" // We use this for the preinstantiated SpiSerial object.
void setup() {
Serial.begin(9600);
Serial.println("SPI UART on WiFly Shield terminal tool");
Serial.println("--------------------------------------");
Serial.println();
Serial.println("This is a tool to help you troubleshoot problems with the WiFly shield.");
Serial.println("For consistent results unplug & replug power to your Arduino and WiFly shield.");
Serial.println("(Ensure the serial monitor is not open when you remove power.)");
Serial.println();
Serial.println("Attempting to connect to SPI UART...");
SpiSerial.begin();
Serial.println("Connected to SPI UART.");
Serial.println();
Serial.println(" * Use $$$ (with no line ending) to enter WiFly command mode. (\"CMD\")");
Serial.println(" * Then send each command followed by a carriage return.");
Serial.println();
Serial.println("Waiting for input.");
Serial.println();
}
void loop() {
// Terminal routine
// Always display a response uninterrupted by typing
// but note that this makes the terminal unresponsive
// while a response is being received.
while(SpiSerial.available() > 0) {
Serial.write(SpiSerial.read());
}
if(Serial.available()) { // Outgoing data
//SpiSerial.print(Serial.read(), BYTE);
SpiSerial.write(Serial.read());
}
}
Sorry I forgot to mention , you reset the shield by going to the WiFly library and going to: WiFly/tools/HardwareFactoryReset
Then open the serial monitor and type in any character and this will start the reset.
Thanks everyone who tried to answer me. I finally solved my problem by using Arduino 0023 instead of 1.0.