NewSoftSerial library is not working for me - arduino

I am trying to get the data from GY-NEO6MV2 GPS and I've tried every solution, but I stil get error:
C:\Users\Szymon\Documents\Arduino\libraries\NewSoftSerial\NewSoftSerial.cpp:43:10: fatal error: WConstants.h: No such file or directory
I use the most simple possible code, it only includes the library and does nothing else, so it's not a problem with my code.
None of the solutions from the internet is working, anybody has an idea why it is not working?

NewSoftSerial is Arduino library for AVR ATmega MCU. It can't be used with other MCU Arduino platforms.

Okay, thank you Juraj for help.
I used the Serial1 to obtain data from the GPS and it worked.
The code if someone also has that problem:
void setup() {
Serial1.begin(9600);
SerialUSB.begin(9600);
}
void loop() {
if (Serial1.available()) {
char outp = Serial1.read();
SerialUSB.print(outp);
}
}

Related

Having trouble programming wifi on esp8266

So I think I'm doing fairly well so far, have the arduino IDE installed, add the ESP8266 module, manage to get an LED blinking on and off. Time to connect to the WIFI and do some stuff.
Unfortunately, it all falls apart then. I get errors about undefined references to wifi_set_opmode, wifi_station_set_config and wifi_station_connect. Now, this isn't my first rodeo with C so I started looking for documentation on these functions and how they are included but can find nothing except people apparently quite happily using them. I've tried adding all sorts of #includes but nothing helps so far. So time to ask for a little help.
Here is the code I am trying to run (pretty uneventful)
#include <user_interface.h>
#define LED_1 13
void setup() {
// put your setup code here, to run once:
pinMode(LED_1, OUTPUT);
const char ssid[32] = "qqqq";
const char password[32] = "wwww";
struct station_config stationConf;
wifi_set_opmode( STATION_MODE );
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 32);
wifi_station_set_config(&stationConf);
wifi_station_connect();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_1, HIGH);
delay(500);
digitalWrite(LED_1, LOW);
delay(500);
}
My board selection is "Generic ESP8266 module"
Here are the errors.
sketch\blinktest.ino.cpp.o:(.text.setup+0x8): undefined reference to `wifi_set_opmode(unsigned char)'
sketch\blinktest.ino.cpp.o:(.text.setup+0x10): undefined reference to `wifi_station_set_config(station_config*)'
sketch\blinktest.ino.cpp.o:(.text.setup+0x14): undefined reference to `wifi_station_connect()'
You need to notice that Arduino is not C, it's based on C++. So add your inclusion like below to use C SDK based functions.
extern "C" {
#include "user_interface.h"
}
Arduino IDE has code examples on menu
File > Examples
There is also example called WiFiWebClient where you need to change only your wifi ssid and password.
Save it to a new folder and you can make http requests to any site on Internet by modifying the address on the example.
Start from the examples of the manufacturer so you don't need to rely on outdated / partial tutorials.

Arduino Serial.read doesn't work

My Arduino Mega (with CH340 but all the drivers needed installed) has stopped reading from the serial port. Doesn´t matter what I write it keeps saving number 50. I have tried with simple examples codes as this one:
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
And I get the same response.
The arduino has been working fine untill today. Serial.print() works also fine, it's just Serial.read() Anyone knows what the problem could be?? I haven't found much help on the internet, seems I am the first one dealing with this issue.
Okay, so I found what my problem was. Don't know if it was Serial.read or Serial println / Serial.write, some of these functions were converting from integers to chars, so numbers appeared to be only between 49 and 58. Using Serial.print instead it works perfectly. Thanks for the answers by the way.

Arduino: serial.read within ISR

I am writing a small test program that attempts to perform a serial.write() followed by a serial.read() within an ISR. The code will eventually be used to prompt an external GSM shield to send an SMS on a regular basis.
ISR(TIMER2_OVF_vect) {
Serial.println("AT+CMGS=\"0123456789\""); // Tell Sim900 To prepare sms to number 01...
while(Serial.read()!='>'); // Wait for Sim900 to respond
Serial.print("A text message"); // the SMS body
Serial.write(0x1A); //Confirm send instruction
Serial.write(0x0D);
Serial.write(0x0A);
}
}
What I have found after a lot of testing is that Serial.read() within an ISR is not capable of reading a live serial prompt, instead it will only read any input that was buffered before the ISR was triggered.
Is there any way around this?
The only solution I have found is to place this code instead within the main loop(). But I want to send the SMS using a timer interrupt.
Thank you
You need to place the code in the loop() but using an IF:
float toBeSent = interval;
loop() {
if (millis() > toBeSent) {
Send();
toBeSent = milli() + interval;
}
}
interval is your sending interval in milliseconds.
I had a similar problem a while ago which I managed to resolve by using the Arduino SoftwareSerial library instead of the hardware based Serial.read.
There are some overheads associated with using SoftwareSerial, and you can only read one port at a time, so I leave it up to those with a better understanding of the Arduino platform to tell you if this is a good idea, but one of the benefits of this library is that you can use it within an ISR.
To use the SoftwareSerial library, add the following two lines of code at the top of your sketch remembering to replqce the rx_pin and tx_pin with the corresponding pin values you want to use:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(rx_pin, tx_pin);
Then replace the key word Serial throughout your sketch with mySerial (or whatever name you have chosen to give your SoftwareSerial instance).
An important thing to keep in mind when using SoftwareSerial is that you can only use certain pins on the Arduino so read the documentation first.
If you wanted to live dangerously you could enable interrupts inside the ISR and use a flag to prevent reentry.
int flag=0;
ISR(TIMER2_OVF_vect) {
flag = 1
if (flag){return;}
sei();
Serial.println("AT+CMGS=\"0123456789\""); // Tell Sim900 To prepare sms to number 01...
while(Serial.read()!='>'); // Wait for Sim900 to respond
Serial.print("A text message"); // the SMS body
Serial.write(0x1A); //Confirm send instruction
Serial.write(0x0D);
Serial.write(0x0A);
}
flag = 0;
}

Arduino Serial Communication not receiving entire message

I have a problem with the Arduino communication. It's quite hard to describe so I cant fit it in the title. Anyway here are the following:
So I have this code for my receiving end:
if(Serial1.available())
{
while(Serial1.available())
{
uint8_t inByte = Serial1.read();
inByte = inByte ^ k;
Serial.write(inByte);
}
Serial.println(" done");
}
It's supposed to print in one line and print done when it's done. The Serial1.available() seems to skip the next Serial1.available(), I don't know what's going on. Anyway here's my current, bad, output:
h done
e done
l done
l done
o done
done
when it should be:
hello done
I'm sorry if this could've been phrased better but that's all I can type now, my brain is kinda in pain. I've never experienced this behavior in a Windows c++ console application.
If you are calling that routine in loop() then yes, it will read from the serial buffer and immediately return since you are probably not sending the data fast enough.
A better way to handle this sort of thing is to use a control char which indicates the end of a message OR if you have a specific data format you expect to receive, then keep a count of the chars which have come in until the data format limit is reached.
There is discussion here which you may find useful: Serial Duplex using Arduino Also there are example sketches that ship with the Arduino IDE: Menu: Examples: Communication:
Also, read all the entries under the Serial listing for Arduino. Good stuff there.
So the routine you develop for working with Serial input really depends on your project and the kind of data you are receiving. In your example above, if you were to use a control char, it might look like this:
while(Serial1.available()){
char c = Serial1.read();
if (c == '*'){
Serial.println(" done");
} else {
Serial.write(c);
}
}

Strange initial output using Serial.print

When I'm writing to the serial interface, I'm getting strange and unexpected output when my sketches first run. The output seems to be a variant of what should be printed:
eg:
String text1 = "foobar";
void setup() {
Serial.begin(9600);
Serial.print("\n");
Serial.print(text1);
}
void loop() {
}
Results in the output:
fo
foobar
(the new line appears before "fo" but I couldn't work out how to include it).
So some variant of whatever is supposed to be printed, gets printed before the actual text that is supposed to be printed. Changing the output, changes the anomalous text (sometimes it'll be two characters, sometimes three). Making changes that don't affect the output and recompiling has no effect on the anomalous text.
I'm a total Arduino newbie (I only started writing my own code today), but I can only assume this isn't normal.
I'm using a Freetronics EtherTen and the 1.0 IDE
thanks in advance
Arduino is restarting your sketch when you open its serial port on the computer.
so it prints out, and then initialized again.
after
Serial.begin(9600);
try to put either:
delay(500)
or
while (!Serial); // while the serial stream is not open, do nothing:
This is most likely a Serial communication Reset issue as Eran W pointed out. See my previous answer here.
The Arduino automatically resets when it receives serial communication from most things other than the Arduino IDE. This is why you can send from the IDE but not anything else.
I have an Uno and put a capacitor between Reset and Ground.Here's a page with some good info on the subject.
Good luck. http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection
You should probably terminate your string with a 0.
Like:
String text1 = "foobar",0;

Resources