Pages: 1 [2]   Go Down
Author Topic: SoftwareSerialExample doesn't work well.  (Read 1384 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The hardware serial is running at 57600 baud so the fact the serial monitor shows rubbish at 4800 is expected. The lower screen shot at 57600 should work, from my understanding of the sketch and your wiring. It correctly shows the output from the local (right) Arduino when you reset it. I assume that the corrupted characters resulted from the reset of the remote (left) Arduino. That should be sending "Hello, world?" but you received something like "C*±±½± °½É± 'ýjRü".

That's not exactly the right number of characters but is roughly the right length, and the "±±" where "ll" should appear suggests that you're seeing a mangled version of the original text.

If you have another USB cable I'd suggest connecting both Arduinos to the PC and open a second instance of the serial monitor to see what you're getting from the left Arduino's hardware serial. It almost looks as if the two boards are running at different speeds or different serial encoding settings, although I don't see any reason why that would happen.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wiring looks fixed. 10 to 11, 11 to 10, GND to GND.
That would be the wiring for soft serial to soft serial though.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's what he should be doing between UNO's isn't it?
Just needs to change the code a wee bit?
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Washington
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm new to arduino i can't figure out how to fix when i get the error like this

sketch_jan28b:0: error: 'SoftwareSerial' does not name a type
sketch_jan28b:0: error: 'Wire.h' does not name a type
sketch_jan28b:0: error: 'NewSoftwareSerial' does not name a type
there is no 'NewSoftwareSerial' on the file
there is no 'wire.h' on the file




Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i'm new to arduino
That's no excuse for not telling us which version of the IDE you are using or posting your code.

Try again.
Logged

Washington
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using ver 1.0

Code:
#include "SoftSerial.h"
#include <string.h>
#include <Wstring.h>

SoftSerial cell(2,3);

int bytesread = 0;
int  val = 0;
char s1[20]= "+CMTI: \"SM\",1";
char s2[20]= "OK";
char s3[20]= "OFF";
char s4[20]= "ON";
int ledpin = 13;   

void setup()
 {
  Serial.begin(9600);
  cell.begin(9600);
  pinMode(ledpin, OUTPUT);

  Serial.println(" ");
  Serial.println("Starting Communication...");

  cell.println("at");
  delay(500);
  cell.println("ate0");
  delay(500);
  cell.println("AT+CMGD=1");    //delete sms at memlocation 2
  delay(1000);

  }
void loop()
 {
  char incoming_ms[20]=" ";
  String buff = String(20);
  if(cell.available() >0)
  {
   if((val = cell.read()) == 10) {   // check for header
    bytesread = 0;
     while(bytesread 0) {
        val = cell.read();
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
           break;                       // stop reading
           }
         incoming_ms[bytesread] = val;         // add the digit
        bytesread++;                   // ready to read next digit
         }
       }
     }
   buff = incoming_ms ;
  // Serial.println(incoming_ms);
  }

 if(buff.contains(s1)&&!buff.contains(s2))
   {
  calling();
 }
}

void calling()
 {
  int i=0;
  int j=0;
  char incoming_let=0;
  char incoming_char[200]=" ";
  String buff1 = String(200);

  cell.println("at+cmgr=1");
  delay(450);
 if(cell.available() >0)
  {
   while(cell.available() >0)
    {
     incoming_let = cell.read();
     incoming_char[j]=incoming_let;
     j++;
     }
   buff1=incoming_char;
   Serial.println(incoming_char);
   change();
  }
 if(buff1.contains(s3))
  {
   Serial.println("done!!!  OFF ");
   digitalWrite(ledpin, LOW);
  // send_off();
   }
 else if(buff1.contains(s4))
  {
  Serial.println("done!!!   ON");
  digitalWrite(ledpin, HIGH);
 // send_on();
  }
 }

void change()
 {
    //Serial.println("Deleting...");
    cell.println("at+cmgd=1");
    delay(500);
 }

 void send_on()
 {
  cell.println("at+cmgf=1");
  delay(1500);
  cell.println("at+cmgs=+91........");
  delay(1500);
  cell.print("Your device is on");
  delay(500);
  Serial.print(0x1A,BYTE);
  delay(1000);
 }

 void send_off()
 {
  cell.println("at+cmgf=1");
  delay(1500);
  cell.println("at+cmgs=+919.........");
  delay(1500);
  cell.print("Your device is off");
  delay(500);
  Serial.print(0x1A,BYTE);
  delay(1000);
 }
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You wrote all that before trying a compile?
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are two classes use for software serial - SoftwareSerial for 1.0 and on and NewSoftSerial for 0023 and earlier.

There is no SoftSerial class.

Code:
  String buff = String(20);
After this, buff = "20". How useful is that?
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3032
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your loop() function looks ridiculous.
Logged

Washington
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if the sketch is made in the libraries Newsoftserial ver 0023 etc,. the sketch will now work in SoftwareSerial?  smiley-confuse

i have no idea if this program works. smiley-cry i just want to know how to fix if i get library errors. tnx


how about this one?

Code:
#include <SoftwareSerial.h>
#include <string.h>

char messagemo[] = "Hello!!! World!!!";

int rxPin = 0;
int txPin = 1;

// set up a new serial port
SoftwareSerial gsm = SoftwareSerial(rxPin,txPin);


void setup() {          
  gsm.begin(9600);  //begin serial communication

  pinMode(rxPin,INPUT);     //rx pin 0 for input
  pinMode(txPin,OUTPUT);  //tx pin 1 for output

  gsm.write("AT\r");
  delay(1000);
  gsm.write("ATE0\r");
  delay(1000);
  gsm.flush();
  gsm.write("AT+CFUN=1\r");
  delay(1000);
  gsm.flush();
  gsm.write("AT+CSDH=0\r");
  delay(1000);
  gsm.write("AT+CMGF=1\r");  //0 kapag PDU, 1 kapag text
  delay(1000);
  gsm.flush();

}


i get this error
prog.cpp:1:28: warning: SoftwareSerial.h: No such file or directory
prog:9: error: 'SoftwareSerial' does not name a type
prog.cpp: In function 'void setup()':
prog:13: error: 'gsm' was not declared in this scope
prog.cpp: In function 'void sendSMS(const char*, const char*)':
prog:44: error: 'gsm' was not declared in this scope
prog.cpp: In function 'void deleteSMS()':
prog:56: error: 'gsm' was not declared in this scope
« Last Edit: January 28, 2013, 11:22:24 am by MrYu2316 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The NewSoftwareSerial class was developed because the old SoftwareSerial class had some serious issues. For 1.0, NewSoftSerial was adopted as an official library, and renamed to SoftwareSerial. So, yes, SoftwareSerial is a direct replacement for NewSoftSerial.

Quote
i just want to know how to fix if i get library errors.
It's better to just not make them.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This compiles in 1.03 with no errors. I used Sketch->Import Library to import SoftwareSerial.
You should be able to do the same with 1.0. Then add the rest of your code a piece at a time running Sketch->Verify/Compile at each stage. You set yourself up for trouble by throwing a mass of code up before verifying any of it.

Code:
#include <SoftwareSerial.h>

SoftwareSerial gsm( 2, 3 );

void setup( void )
{
  gsm.begin(9600);  //begin serial communication
}

void loop( void )
{
}

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The hardware serial is running at 57600 baud so the fact the serial monitor shows rubbish at 4800 is expected. The lower screen shot at 57600 should work, from my understanding of the sketch and your wiring. It correctly shows the output from the local (right) Arduino when you reset it. I assume that the corrupted characters resulted from the reset of the remote (left) Arduino. That should be sending "Hello, world?" but you received something like "C*±±½± °½É± 'ýjRü".

That's not exactly the right number of characters but is roughly the right length, and the "±±" where "ll" should appear suggests that you're seeing a mangled version of the original text.

If you have another USB cable I'd suggest connecting both Arduinos to the PC and open a second instance of the serial monitor to see what you're getting from the left Arduino's hardware serial. It almost looks as if the two boards are running at different speeds or different serial encoding settings, although I don't see any reason why that would happen.


I connected USB cables to both Arduinos.
And I tried both "soft to soft" and "soft to hard" connections, and
both bauds as shown in soft2soft.jpg and soft2hard.jpg.
But, it can't work.
I put screenshots of serial monitors. When I took them, I pushed both
the reset buttons of the Arduinos once each.
In the screenshots, COM16 is the left Arduino in soft2soft.jpg and
soft2hard.jpg, and COM17 is the right.
I changed the Arduinos to new ones, but the result was same.

I can't upload all files for the maximum attachment size allowed, so I do only files of "soft to soft".
I'll upload files of "soft to hard" in my next comment.


* soft2soft.jpg (468.01 KB, 2560x1920 - viewed 23 times.)

* soft2soft4800.jpg (39.44 KB, 902x649 - viewed 18 times.)

* soft2soft57600.jpg (42.53 KB, 900x651 - viewed 16 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I upload the files of "soft to hard".


* soft2hard.jpg (461.98 KB, 2560x1920 - viewed 18 times.)

* soft2hard4800.jpg (39.41 KB, 908x650 - viewed 17 times.)

* soft2hard57600.jpg (40.71 KB, 902x655 - viewed 18 times.)
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

More troubleshooting then. Time to nail down when and where the failure takes place.

Maybe try a delay() before and after Serial.begin() in setup()?

Or hold up soft-soft serial until user-i/o from serial monitor transmits "GO" in response to prompt and led 13 ON on both UNO's to show each is initialized?
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: 1 [2]   Go Up
Jump to: