Description of problem
[x] PlatformIO Core.
Hello, I use PlatformIO to compile & update code for a remote servo system on an STM32F411-based system. Everything was working fine, but while working on a new update something broke. So I reverted the project to the last stable release and I am still getting the same compiler error.
With the reverted build, platformio fails with:
ImportError: cannot import name 'Serial' from 'serial'
So then I downgraded to 4.3.3 and it failed with
'Serial' does not name a type; did you mean 'serial_t'?
Anyway, hopefully I haven’t made a big goof, but I’m not sure how to proceed.
I believe that it broke on the remote machine as well, but I will double check.
Configuration
Operating system:
Linux g7 5.4.0-42-generic platformio/platformio-core#46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
PlatformIO Version (platformio --version
):
4.3.4 & 4.3.3
; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; http://docs.platformio.org/page/projectconf.html [env:nucleo_f411re] platform = ststm32 board = nucleo_f411re framework = mbed debug_tool = stlink upload_protocol = stlink build_flags = -ggdb -g3
Source file to reproduce issue:
#include "mbed.h" #include "QEI.h" //#include "../lib/UART_ISR.h" #include "../lib/PinDefs.h" #include "../lib/MotorTests.h" #include "../lib/PID.h" void serial_update(void); void control_loop(void); Ticker ticker; void mot1_set(float); void mot2_set(float); Serial pc(PA_11, PA_12); //tx, rx; PID pid1(0.0175, 0.0, 0.1, &wheel1, &ticker); PID pid2(0.0134, 0.0, 0.1, &wheel2, &ticker); int main(){ pc.baud(PC_BAUD); buzzer.period(0.0015); buzzer = 0.5; wait_us(500000); buzzer = 0; m1in1 = 0; m1in2 = 1; m1d1 = 1; m1d1.period(.00005); m2in1 = 0; m2in2 = 1; m2d1 = 1; m2d1.period(.00005); //pc.attach(&rxIsr); ticker.attach_us(&control_loop, 5000.0); while(1) { serial_update(); } } void control_loop(void){ mot1_set(pid1.update()); mot2_set(pid2.update()); } // Updates PID setpoints from new serial input void serial_update(void){ //Only update if there is new line in the serial buffer //t.reset(); if(newlineFlag == 1){ string local; local = in1; newlineFlag = 0; //Check to see which wheel to update if((local.find(left) == 0) & (local.find(end_char) == local.length()-1)){ local.erase(local.begin()); local.erase(local.end()-1); int dl; dl = std::atoi(local.c_str()); pid2.setpoint += dl; pc.printf("L:%irn", dl); } if((local.find(right) == 0) & (local.find(end_char) == local.length()-1)){ local.erase(local.begin()); local.erase(local.end()-1); int dr; dr = std::atoi(local.c_str()); pid1.setpoint -= dr; pc.printf("R:%irn", dr); } if((local.find(test_command) == 0) & (local.find(end_char) == local.length()-1)){ test_t pid_test; local.erase(local.begin()); local.erase(local.end()-1); const char * c_str = local.c_str(); int side; sscanf(c_str, "%d,%f,%f,%f,%f", &side, &pid_test.p, &pid_test.i, &pid_test.d, &pid_test.setpoint); if (side == 1){ pid1.tune(pid_test); }else if(side == 2){ pid2.tune(pid_test); } } } }
Compile Errors
Results with the newest version of platformio:
Processing nucleo_f411re (platform: ststm32; board: nucleo_f411re; framework: mbed)
-----------------------------------------------------------------------------------------------------
ImportError: cannot import name 'Serial' from 'serial' (/home/brett/anaconda3/lib/python3.7/site-packages/serial/__init__.py):
File "/home/brett/anaconda3/lib/python3.7/site-packages/platformio/builder/main.py", line 89:
env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS)
File "/home/brett/.platformio/packages/tool-scons/script/../engine/SCons/Defaults.py", line 88:
_default_env = SCons.Environment.Environment(*args, **kw)
File "/home/brett/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 990:
apply_tools(self, tools, toolpath)
File "/home/brett/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 102:
env.Tool(tool)
File "/home/brett/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 1809:
tool = SCons.Tool.Tool(tool, toolpath, **kw)
File "/home/brett/.platformio/packages/tool-scons/script/../engine/SCons/Tool/__init__.py", line 122:
module = self._tool_module()
File "/home/brett/.platformio/packages/tool-scons/script/../engine/SCons/Tool/__init__.py", line 239:
module = spec.loader.load_module(spec.name)
File "<frozen importlib._bootstrap_external>", line 407:
File "<frozen importlib._bootstrap_external>", line 907:
File "<frozen importlib._bootstrap_external>", line 732:
File "<frozen importlib._bootstrap>", line 265:
File "<frozen importlib._bootstrap>", line 696:
File "<frozen importlib._bootstrap>", line 677:
File "<frozen importlib._bootstrap_external>", line 728:
File "<frozen importlib._bootstrap>", line 219:
File "/home/brett/anaconda3/lib/python3.7/site-packages/platformio/builder/tools/pioupload.py", line 26:
from serial import Serial, SerialException
So then I tried to rollback to version 4.3.3 and got a different error
***********************************************************************************
Obsolete PIO Core v4.3.3 is used (previous was 4.3.4)
Please remove multiple PIO Cores from a system:
https://docs.platformio.org/page/faq.html#multiple-pio-cores-in-a-system
***********************************************************************************
Processing nucleo_f411re (platform: ststm32; board: nucleo_f411re; framework: mbed)
-----------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f411re.html
PLATFORM: ST STM32 8.0.0 > ST Nucleo F411RE
HARDWARE: STM32F411RET6 100MHz, 128KB RAM, 512KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:
- framework-mbed 6.60200.200722 (6.2.0)
- toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
...
src/main.cpp: At global scope:
src/main.cpp:15:1: error: 'Serial' does not name a type; did you mean 'serial_t'?
Serial does not name a type error
— Thu Mar 03, 2016 10:08 pm
#188511
When this sketch is executed this error results. What needs to be accomplished with this code is for 8 voltage readings from the 74HC4015 to be displayed on the serial monitor. I’m new to programming.
Thank you
AnalogMultiplexing:43: error: ‘Serial’ does not name a type
Serial.print(«Raw Value = » );
AnalogMultiplexing:44: error: ‘Serial’ does not name a type
Serial.print(RawValue);
^
exit status 1
‘Serial’ does not name a type
Code: Select all
int pin_Out_S0 = 8;
int pin_Out_S1 = 9;
int pin_Out_S2 = 10;
int pin_In_Mux1 = A0;
int Mux1_State[8] = {0};
//float Mux1_State[i] =0;
int RawValue=0;
float Voltage = 0;
void setup() {
pinMode(pin_Out_S0, OUTPUT);
pinMode(pin_Out_S1, OUTPUT);
pinMode(pin_Out_S2, OUTPUT);
pinMode(pin_In_Mux1, INPUT);
Serial.begin(9600);
}
void loop() {
RawValue = analogRead(pin_In_Mux1);
Voltage = (RawValue * 5.0) / 1024; //scale the ADC
updateMux1();
//Serial.println(Mux1_State);
for(int i = 0; i < 8; i ++) {
if(i == 7) {
Serial.println(Mux1_State[i]);
} else {
Serial.print(Mux1_State[i]);
Serial.print(",");
// vout = (value * 5.0) / 1024.0;
}
}
}
void updateMux1 () {
for (int i = 0; i < 8; i++){
digitalWrite(pin_Out_S0, HIGH && (i & B00000001));
digitalWrite(pin_Out_S1, HIGH && (i & B00000010));
digitalWrite(pin_Out_S2, HIGH && (i & B00000100));
Mux1_State[i] = analogRead(pin_In_Mux1);
}
}
Serial.print("Raw Value = " );
Serial.print(RawValue);
— Fri Mar 04, 2016 9:38 am
#188513
That’s because it’s outside of Loop().
Code: Select all
int pin_Out_S0 = 8;
int pin_Out_S1 = 9;
int pin_Out_S2 = 10;
int pin_In_Mux1 = A0;
int Mux1_State[8] = {0};
//float Mux1_State[i] =0;
int RawValue=0;
float Voltage = 0;
void setup() {
pinMode(pin_Out_S0, OUTPUT);
pinMode(pin_Out_S1, OUTPUT);
pinMode(pin_Out_S2, OUTPUT);
pinMode(pin_In_Mux1, INPUT);
Serial.begin(9600);
}
void loop() {
RawValue = analogRead(pin_In_Mux1);
Voltage = (RawValue * 5.0) / 1024; //scale the ADC
updateMux1();
//Serial.println(Mux1_State);
for(int i = 0; i < 8; i ++) {
if(i == 7) {
Serial.println(Mux1_State[i]);
} else {
Serial.print(Mux1_State[i]);
Serial.print(",");
// vout = (value * 5.0) / 1024.0;
}
}
Serial.print("Raw Value = " );
Serial.print(RawValue);
}
void updateMux1 () {
for (int i = 0; i < 8; i++){
digitalWrite(pin_Out_S0, HIGH && (i & B00000001));
digitalWrite(pin_Out_S1, HIGH && (i & B00000010));
digitalWrite(pin_Out_S2, HIGH && (i & B00000100));
Mux1_State[i] = analogRead(pin_In_Mux1);
}
}
————————————————————————————————————————————————————
//codlink
Available for circuit and PCB design, just PM me!
Hello!
I am trying to read the voltage of my 3.7V battery connected to a Feather MO. I found this in the documentation here.
https://learn.adafruit.com/adafruit-fea … management
————————————————————————————————————————————————————————————————————————————
#define VBATPIN A7
float measuredvbat = analogRead(VBATPIN);
measuredvbat *= 2; // we divided by 2, so multiply back
measuredvbat *= 3.3; // Multiply by 3.3V, our reference voltage
measuredvbat /= 1024; // convert to voltage
Serial.print(«VBat: » ); Serial.println(measuredvbat);
————————————————————————————————————————————————————————————————————————————
I’m confused because it compiled yesterday with no problems, and today I tried to compile it, and I got the below error.
————————————————————————————————————————————————————————————————————————————
BAT:4:1: error: ‘measuredvbat’ does not name a type
measuredvbat *= 2; // we divided by 2, so multiply back
^
BAT: error: ‘measuredvbat’ does not name a type
measuredvbat *= 3.3; // Multiply by 3.3V, our reference voltage
^
BAT:6:1: error: ‘measuredvbat’ does not name a type
measuredvbat /= 1024; // convert to voltage
^
BAT:7:1: error: ‘Serial’ does not name a type
Serial.print(«VBat: » ); Serial.println(measuredvbat);
^
BAT:7:26: error: ‘Serial’ does not name a type
Serial.print(«VBat: » ); Serial.println(measuredvbat);
^
exit status 1
‘measuredvbat’ does not name a type
————————————————————————————————————————————————————————————————————————————
I am very confused. I was hoping someone could point me in the right direction. Thank you so much!!
📷
LukeP1042 Posts: 1Joined: Fri May 10, 2019 10:08 pm
Topic: SoftSerial example not compiling (Read 9814 times)
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:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
Telling me that:
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:
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
Logged
Hello Jusep,
Did you create the serial object?
Something like
#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
Logged
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.
/*
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());
}
Logged