Notifications
Clear all

PlatformIO fejl

11 Posts
3 Users
1 Likes
1,648 Views
henrik_t7
(@henrik_t7)
Member
Joined: 3 years ago
Posts: 15
Topic starter  

PlatformIO error why does it not work ?? I have tried to compile a file in Visual Studio Code / PlatformIo, but it makes a mistake ?? And when I then compile the same file in Arduino IDE v1.8.13 it makes no mistake. Why Visual Studio Code / PlatformIo Makes Errors Thanks

PlatformIO

fejl1

Arduino IDE

fejl2

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif

#define PIN 6

// MATRIX DECLARATION:
// Parameter 1 = width of the matrix
// Parameter 2 = height of the matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the matrix; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
// rows or in vertical columns, respectively; pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
// in the same order, or alternate lines reverse direction; pick one.
// See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_GRBW Pixels are wired for GRBW bitstream (RGB+W NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);

const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(255, 106, 0), matrix.Color(255, 255, 0), matrix.Color (0, 255, 0),
matrix.Color (0, 0, 255), matrix.Color (112, 39, 195), matrix.Color (255, 0, 255)};

void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(10);
matrix.setTextColor(colors[0]);
}

int x = matrix.width();
int pass = 0;

void loop() {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(F("Hej Mie"));
if(--x < -36) {
x = matrix.width();
if(++pass >= 7) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(100);
}


   
Quote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

Your file in PlatformIO is an INO file and not the CPP that you want to use in PlatformIO. Also, I do not see the Arduino.h file included at the top. The Arduino IDE does this for you automatically but in PlatformIO, you need to always include it. PlatformIO also seems to think you are uploading it to an Uno but you have a reference to a Due board so I suspect there might be an issue there.

 

If you are having trouble getting used to PlatformIO, there is an alternative. As long as you have the Arduino IDE installed on the same computer, you can install the Arduino extension from Microsoft. It is much easier and acts like the Arduino IDE. You can easily select what board you are using and it will include the correct library for you. It still has InteliSense/predictive suggestions, error checking and thanks to git you have a library version tracker/manager

 

To be honest, most of the benefits I see stated for PlatformIO are actually benefits of using Visual Studio Code. Do what is comfortable for you.


   
NewburyPi reacted
ReplyQuote
henrik_t7
(@henrik_t7)
Member
Joined: 3 years ago
Posts: 15
Topic starter  

Hi

Thanks for reply.

Where can I find "Arduino extension from Microsoft" should this install in PlatformIO or what ??

thanks 😀 😀 


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 
Posted by: @henrik_t7

Hi

Thanks for reply.

Where can I find "Arduino extension from Microsoft" should this install in PlatformIO or what ??

thanks 😀 😀 

No, it is a different extension. I believe you actually have to disable PlatformIO for it to work, but I believe it should ask you if that is the case. Just click on extensions on the left(or Ctrl+Shift+X at least on Windows) and search for Arduino. It should be near the top and be signed by Microsoft.


   
ReplyQuote
NewburyPi
(@dale)
Member
Joined: 5 years ago
Posts: 97
 

Luckily PlatformIO does not steal the Arduino IDE extension (as I remember). No need to disable PIO.
There is an issue with installing Arduino, if you want to use it with PIO. You need to take the stand alone download. Take the windows download, not the windows app. See:

https://www.arduino.cc/en/software

Screenshot 20210325 174753 Chrome

 

--
Dale


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 
Posted by: @dale

Luckily PlatformIO does not steal the Arduino IDE extension (as I remember). No need to disable PIO.

Disabling PIO was because there might be conflicts in VSC because both extensions want to work on the same files and if I remember right, as soon as I installed the extension, I thought it asked me to disable PIO but that was a long time ago and my memory is bad. That and they have made so many improvements to PIO that it might have been fixed.


   
ReplyQuote
NewburyPi
(@dale)
Member
Joined: 5 years ago
Posts: 97
 

I suppose it depends on the extensions you enable in VSC. I have been running PIO and Arduino IDE simultaneously for the past (at least) two years. I've loaded extensions for C++ and Python and have had no problems. 

Looking at @henrik_t7 's code above, it looks like he is missing the 

#include <Arduino.h>
Which is necessary to work with Arduino libraries within PIO. 

--
Dale


   
ReplyQuote
henrik_t7
(@henrik_t7)
Member
Joined: 3 years ago
Posts: 15
Topic starter  

Hi

Thank you very much for all the answers. 

But I can not figure out how to use PlatformIO and I found it too cumbersome to code in PlatformIO, so I use Arduino IDE. It will also have a new edition coming soon.

Thank you and happy Easter


   
ReplyQuote
NewburyPi
(@dale)
Member
Joined: 5 years ago
Posts: 97
 

@henrik_t7, the Arduino IDE is a great tool for most new programmers. It allows you to plow right into writing code for your projects. As you advance your skills, you may find that it doesn't do everything you need. You'll find yourself saying "if only it could react more quickly," or "why can't I just do this." You may find that writing C or C++ will help you answer these questions. At that time, you will be more knowledgeable of the underpinnings of Arduino, and transitioning to a more advanced IDE will be much easier. In the mean time, enjoy the learning.

--
Dale


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 
Posted by: @henrik_t7

Hi

Thank you very much for all the answers. 

But I can not figure out how to use PlatformIO and I found it too cumbersome to code in PlatformIO, so I use Arduino IDE. It will also have a new edition coming soon.

Thank you and happy Easter

The new version of Arduino IDE looks like it will do much of the same as using the Arduino extension in Visual Studio Code(looks and function). If you are willing to wait then that might be your answer. IMHO, the greatest benefit of Visual Studio Code is just to have a common and comfortable place to do most of your coding in. I can have all my shortcuts the same no matter if I an writing Python, Java SIMPL or building an Arduino project. As well as it is just easier on my eyes and considering I can be staring at it for hours, that is actually a big deal for me.

 

But, from what I hear, they are working out a lot of bugs and i could either take some time or the early adopters might have to work through some of the problems. You can join the Beta program but I don't know if you can keep the old IDE installed.

 

Also, the new version looks like it will look and behave exactly like the Arduino extension in Visual Studio Code. If you want to see what that experience is like then I would install the Arduino extension. It wouldn't hurt anything. I would still disable PlatformIO just to be sure there are no problems. If you make a new file just make sure it is named with .ino after it, That's about all you need to remember to do with that extension. No need to include the board header files, the Arduino extension takes care of all that for you. And selecting the board and port for your terminal is fairly easy to see.


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

@henrik_t7

I realize that I really didn't answer your questions from your second post very well at all. That was my mistake.

So to clear things up a little. Unfortunately, most of the videos you see compare Arduino IDE to PlatformIO and maybe mention once that PlatformIO is just an extension in Visual Studio Code but after making comparison between the two, it can be confusing. So here is a step by step guide if you are still interested.

VSC1

Open Visual Studio Code, click the button labeled above as 1, then in the field labeled as 2 type "Arduino" and search. It should be the first one there published by Microsoft. the place labeled 3 will have an install button. That is it. You might want to disable PlatformIO by searching for it in the same place. By disabling it, when you open a file that is .ino, it will then automatically use this extension.

 

I suggest that you have a file system of folder for your project and when you want to switch projects just go to File->Open Folder. This will bring show all the sketches you have in that folder.

VSC2

To make a new sketch just hit the button the arrow is pointing to above and name it what you want and .ino at the end.

 

I did forget earlier that you do need to put in the void setup and loop sections. You can copy and paste directly from a new file from the Arduino IDE until you remember how it goes(it's not that much).

VSC3

Top right corner has your compile and upload.

Bottom right of screen in the blue bar is you board selection, programmer, Com port. Here, if you click on them will have all the options you have in Arduino IDE menus. Hit the little plug for serial monitor to open.

 

Once you are comfortable with Visual Studio Code and Arduino/C++, you can always disable it and reenable PlatformIO. But the beauty of Visual Studio Code is that, you can easily open a Python file and immediately start editing it with all the suggestions and debugging you need, as well as run it directly form there. That's fairly impressive considering that Visual Studio Code is not an IDE!


   
ReplyQuote