The Digispark > Digispark Libraries
SoftSerial example not compiling
(1/1)
jusep:
Hi all!
I have a Digispark with a thermometer shield I designed. Now, I would like to make some reading to the sensor and send them to the computer. I would like to have a bidirectional communication between the PC and the Digispark. To do so, I thought that the SoftSerialExample would be a good starting point. However, I encountered some issues. First, there was a compiling error in line:
--- Code: ---while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
--- End code ---
Telling me that:
--- Code: ---tmp/arduino_modified_sketch_408992/SoftSerialExample.ino: In function 'void setup()':
SoftSerialExample:32: error: no match for 'operator!' (operand type is 'TinyDebugSerial')
while (!Serial) {
^
/tmp/arduino_modified_sketch_408992/SoftSerialExample.ino:32:11: note: candidate is:
/tmp/arduino_modified_sketch_408992/SoftSerialExample.ino:32:11: note: operator!(bool) <built-in>
/tmp/arduino_modified_sketch_408992/SoftSerialExample.ino:32:11: note: no known conversion for argument 1 from 'TinyDebugSerial' to 'bool'
exit status 1
no match for 'operator!' (operand type is 'TinyDebugSerial')
--- End code ---
However, given that this line is needed for Leornardo only I commented it. Next, however, more compiling errors appear:
--- Code: ---
SoftSerialExample:37: error: 'Serial' does not name a type
Serial.println("Goodnight moon!");
^
SoftSerialExample:40: error: 'mySerial' does not name a type
mySerial.begin(4800);
^
SoftSerialExample:41: error: 'mySerial' does not name a type
mySerial.println("Hello, world?");
^
SoftSerialExample:42: error: expected declaration before '}' token
}
^
exit status 1
'Serial' does not name a type
--- End code ---
I am clueless on how to fix it. Could you please give me some guidance? I am using Arduino IDE 1.8.5 on an Ubuntu 14.04 LTS.
Thanks in advance!
Jusep
robvd:
Hello Jusep,
Did you create the serial object?
Something like
--- Code: --- #include <SoftSerial.h> // SoftSerial en TinyPinChange voor DigiSpark
#include <TinyPinChange.h>
SoftSerial MySerial(RX, TX); // RX, TX pins
--- End code ---
Also the "}" error may be the problem. Sometimes the errors are not clear when something else is wrong and one } to many or too few may give all kind of errors….
Rob
Rob
jusep:
Hi Rob,
I am using the example code provided when you install Digispark board on Arduino IDE. Of course, the serial object is created.
Talking with a friend some days ago he proposed to use DigiCDC library for this purpose, so I'll give it a try.
--- Code: ---/*
Software serial multiple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.
The circuit:
* RX is digital pin 2 (connect to TX of other device)
* TX is digital pin 3 (connect to RX of other device)
created back in the mists of time
modified 9 Apr 2012
by Tom Igoe
based on Mikal Hart's example
This example code is in the public domain.
<SoftSerial> adapted from <SoftwareSerial> for <TinyPinChange> library which allows sharing the Pin Change Interrupt Vector.
Single difference with <SoftwareSerial>: add #include <TinyPinChange.h> at the top of your sketch.
RC Navy (2012): http://p.loussouarn.free.fr
*/
#include <SoftSerial.h> /* Allows Pin Change Interrupt Vector Sharing */
#include <TinyPinChange.h> /* Ne pas oublier d'inclure la librairie <TinyPinChange> qui est utilisee par la librairie <RcSeq> */
SoftSerial mySerial(2, 3); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
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());
}
--- End code ---
Navigation
[0] Message Index
Go to full version