Author Topic: SoftSerial example not compiling  (Read 572 times)

jusep

  • Newbie
  • *
  • Posts: 2
SoftSerial example not compiling
« on: June 24, 2018, 11:40:37 am »
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: [Select]
while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

Telling me that:
Code: [Select]
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')

However, given that this line is needed for Leornardo only I commented it. Next, however, more compiling errors appear:
Code: [Select]


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


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

  • Newbie
  • *
  • Posts: 3
Re: SoftSerial example not compiling
« Reply #1 on: July 08, 2018, 01:41:40 pm »
Hello Jusep,

Did you create the serial object?

Something like

Code: [Select]
  #include <SoftSerial.h>                 // SoftSerial en TinyPinChange voor DigiSpark               
  #include <TinyPinChange.h>
  SoftSerial MySerial(RX, TX);     // RX, TX pins

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

  • Newbie
  • *
  • Posts: 2
Re: SoftSerial example not compiling
« Reply #2 on: July 12, 2018, 12:34:11 am »
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: [Select]
/*
  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());
}