#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); void setup() { Serial.begin(57600); Serial.println("Goodnight moon!"); // set the data rate for the SoftwareSerial port mySerial.begin(4800); mySerial.println("Hello, world?"); } void loop() // run over and over { if (mySerial.available()) Serial.write(mySerial.read()); if (Serial.available()) mySerial.write(Serial.read()); }
При подключении (установки коннекта) будет выводить в порт один раз Goodnight moon! и/или Hello, world? самый верный способ - воткнуть и проверить...
У меня выводит просто GoodMoon и все. Дальше, чтобы я не вводил с клавиатуры, ничего больше не выводится. Тогда я не понимаю смысл softwareserial. Я не могу понять, как он работает. У меня есть bluetooth shield и gprs shield, и работа с ними происходит как раз через эту библиотеку, но shield-ы ничего не отвечают, как и этот код.
Вам нужно посмотреть примеры работ с платами расширения, тут рассматривают пример с ДжиПиЭс с ардуино http://habrahabr.ru/post/108797/ http://arduino.cc/playground/Tutorials/GPS
/* SparkFun Cellular Shield - Pass-Through Sample Sketch SparkFun Electronics Written by Ryan Owens CC by v3.0 3/8/10 Thanks to Ryan Owens and Sparkfun for sketch */ #include <NewSoftSerial.h> //Include the NewSoftSerial library to send serial commands to the cellular module. #include <string.h> //Used for string manipulations char incoming_char=0; //Will hold the incoming character from the Serial Port. NewSoftSerial cell(7,8); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin. void setup() { //Initialize serial ports for communication. Serial.begin(9600); cell.begin(9600); Serial.println("Starting SM5100B Communication..."); } void loop() { //If a character comes in from the cellular module... if(cell.available() >0) { incoming_char=cell.read(); //Get the character from the cellular serial port. Serial.print(incoming_char); //Print the incoming character to the terminal. } //If a character is coming from the terminal to the Arduino... if(Serial.available() >0) { incoming_char=Serial.read(); //Get the character coming from the terminal cell.print(incoming_char); //Send the character to the cellular module. } } На вот такой код после Starting SM5100B Communication... в сериал пишется ÿÿÿÿÿÿÿÿ
У вас из cell или Serial сваливается значене 255 (ÿ = 255 из аски) если отключать и подключать "устройство в "нагорячую"" на 7,8 порту, значение меняется?