PlatformIO Community

Code complies but doesn't seem to do anything

New to Arduino and PIO, so forgive me if this is a dumb question.

The code is rather simple. Just lighting up a single-digit 7-segment display,

#include "SevSeg.h"
SevSeg sevseg; 

void setup(){
    byte numDigits = 1;
    byte digitPins[] = {};
    byte segmentPins[] = {6, 5, 2, 3, 4, 7, 8, 9};
    bool resistorsOnSegments = true;

    byte hardwareConfig = COMMON_CATHODE; 
    sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
    sevseg.setBrightness(90);
}

void loop(){
        sevseg.setNumber(5);
        sevseg.refreshDisplay();        
}

The code compiles with both PIO and Arduino IDE, but only Arduino IDE uploaded one will show a number “5”.

The board is an Arduino Uno 3. Here is a screenshot of the tools menu.

image

platformio.ini is almost default with library SevSeg added.

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = deanisme/SevSeg@^3.7.0

Here is the build log, where I don’t see any error.

Processing uno (platform: atmelavr; board: uno; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Removing unused dependencies...
Library Manager: Installing deanisme/SevSeg @ ^3.7.0
Unpacking  [####################################]  100%
Library Manager: SevSeg@3.7.0 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (4.0.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.1.0
 - tool-avrdude @ 1.60300.200527 (6.3.0)
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 6 compatible libraries
Scanning dependencies...
Dependency Graph
|-- SevSeg @ 3.7.0
Building in release mode
Compiling .pio\build\uno\src\main.cpp.o
Compiling .pio\build\uno\lib18e\SevSeg\SevSeg.cpp.o
Archiving .pio\build\uno\libFrameworkArduinoVariant.a
Compiling .pio\build\uno\FrameworkArduino\CDC.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial0.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial1.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial2.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial3.cpp.o
Compiling .pio\build\uno\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\uno\FrameworkArduino\PluggableUSB.cpp.o
Compiling .pio\build\uno\FrameworkArduino\Print.cpp.o
Compiling .pio\build\uno\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\uno\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\uno\FrameworkArduino\USBCore.cpp.o
Compiling .pio\build\uno\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\uno\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\uno\FrameworkArduino\WString.cpp.o
Compiling .pio\build\uno\FrameworkArduino\abi.cpp.o
Archiving .pio\build\uno\lib18e\libSevSeg.a
Compiling .pio\build\uno\FrameworkArduino\hooks.c.o
Compiling .pio\build\uno\FrameworkArduino\main.cpp.o
Compiling .pio\build\uno\FrameworkArduino\new.cpp.o
Compiling .pio\build\uno\FrameworkArduino\wiring.c.o
Compiling .pio\build\uno\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\uno\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\uno\FrameworkArduino\wiring_pulse.S.o
Compiling .pio\build\uno\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\uno\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\uno\libFrameworkArduino.a
Linking .pio\build\uno\firmware.elf
Checking size .pio\build\uno\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.4% (used 9 bytes from 2048 bytes)
Flash: [          ]   1.4% (used 444 bytes from 32256 bytes)
Building .pio\build\uno\firmware.hex
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: COM3
Uploading .pio\build\uno\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file ".pio\build\uno\firmware.hex"
avrdude: writing flash (444 bytes):

Writing | ################################################## | 100% 0.08s

avrdude: 444 bytes of flash written
avrdude: verifying flash memory against .pio\build\uno\firmware.hex:
avrdude: load data flash data from input file .pio\build\uno\firmware.hex:
avrdude: input file .pio\build\uno\firmware.hex contains 444 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.07s

avrdude: verifying ...
avrdude: 444 bytes of flash verified

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

===================================================================================================================================================== [SUCCESS] Took 3.42 seconds ====================================================================================================================================================

What did I miss here? Thanks!

That is uh, very interesting.

Does the standard blinking LED code work though on your Uno + PlatformIO?

In the Arduino IDE, what’s the version of the AVR core installed? (Tools → Board → Board Manager → avr).

What’s the version of the used SevSeg library? (Library is probably in C:\Users\<user>\Documents\Arduino\libraries\SevSeg, version is in library.properties).

Hmmm, it doesn’t work. That’s really weird. Initially I tried this code with Microsoft’s Arduino extension which worked perfectly fine. I tried to remove #include <Arduino.h> and manually define LED_BUILTIN, but result was the same.

It’s 1.8.6.

My OneDrive space is running low, so I moved my sketchbook location to %LOCALAPPDATA%/Arduino15. The version is 3.7.0, but I guess SevSeg is irrelevant now if the LED code doesn’t even work.

Maybe I missed some important settings in PIO?


Edit: I found why… I have to throw the code in src/main.cpp :joy: Instead of a random *.ino file. If I overwrite src/main.cpp with my codes, PIO compiled one will work.

Sorry about this.

Can you try this with only the original PlatformIO extension installed, not any other Arduino / PIO clone extension?

Oops, you replied before my editing. So the problem was that I didn’t code in the src folder.