Arduino has an official CLI app now
Has anyone tried using it to create a MySensors device?
To try it:
tar xvjf arduino-cli-0.3.3-alpha.preview-linuxarm.tar.bz2
While you're at it, rename the executable:
mv arduino-cli-0.3.3-alpha.preview-linuxarm arduino-cli
Et voila! Try:
Try commands like:
Updating the index (you may have to do this to get the latest updates):
./arduino-cli core update-index
Download the software for the AVR family (If you want to upload to the Arduino Nano, for example.)
./arduino-cli core install arduino:avr
Create a new sketch:
arduino-cli sketch new MyFirstSketch
Edit the sketch:
Get a list of all attached boards (I believe it also scans the network):
./arduino-cli board list
Compile the code for you device. This is an example for the Arduino Nano:
./arduino-cli compile --fqbn arduino:avr:nano $HOME/Arduino/MyFirstSketch
(FQBN = Fully Qualified Board Name)
If you want to install certain libraries (like MySensors), you can find them like this:
./arduino-cli lib search MySensors
And install them like this:
./arduino-cli lib install "MySensors"
If you want to install an older version of a library, try this:
./arduino-cli lib install "MySensors@2.1.0"
Finally, after compiling you can try to upload it. For this you will need to get the USB serial port name. After plugging in the Arduino you can try finding it by checking:
You will find something like /dev/ttyUSB0 or /dev/ttyACM0
Then, use that name in the upload command. I'm using 'ttyUSB0' in this example:
./arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano $HOME/Arduino/MyFirstSketch -t -v
or if you have older Arduino Nano's with the old bootloader:
./arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328old $HOME/Arduino/MyFirstSketch -t -v
In the above commands you will see:
- t ..this checks if everything wen well after uploading
- v ..this means 'verbose', and will result in much more details being spewed out onto your screen about the progress of the upload.
If you want to know more about what a command is doing under the hood, then just add a space followed by --debug to the end of it.
You can get the current configuration with this command:
./arduino-cli config dump
To learn more about a certain command, in this case the upload command, try:
./arduino-cli help upload
No, I haven't. I guess I don't plan on it either. Have you heard of platformio?
It's pretty damn handy. For those that wish, it has a better IDE than Arduino, fetches dependencies as specified, and above all has a great CLI. If you're interested in compiling and uploading binaries from the CLI, I would recommend you have a look at:
I know it doesn't answer your question, but I like to have a proper C++ linter running, letting a computer work for me, documenting exactly what I did to get code compiling and uploading, and to edit code in a proper editor.
A quick start with platformio could be:
pip install platformio git clone https://github.com/oneyb/template-mysensors-platformio blink cd blink # Do some stuff $EDITOR platformio.ini src/*cc # and finally: pio run -t upload
I hope that helps you to be more efficient. It sure has helped me.
artag last edited by
I installed platformio a while back for experiments with ice40. I've avoided it ever since because I found it way overcomplicated (and I generally prefer CLI environments - it just seemed that by trying to tackle everything it was reinventing too many wheels and had too many dependencies).
But inspired by your delightfully simple example, I reinstalled it and had another go. It up did some updates (including to ice40, which surprised me), but failed in building blink with :
Compiling .pioenvs/mysensors_htu21d/FrameworkArduino/HardwareSerial0.cpp.o src/mysensor-code.cc:64:1: error: 'HTU21D' does not name a type HTU21D myHumidity; ^ src/mysensor-code.cc: In function 'void setup()': src/mysensor-code.cc:97:3: error: 'myHumidity' was not declared in this scope myHumidity.begin(); ^ src/mysensor-code.cc: In function 'void readHTU21DTemperature(bool)': src/mysensor-code.cc:148:16: error: 'myHumidity' was not declared in this scope float temp = myHumidity.readTemperature(); ^ src/mysensor-code.cc: In function 'void readHTU21DHumidity(bool)': src/mysensor-code.cc:171:16: error: 'myHumidity' was not declared in this scope float humd = myHumidity.readHumidity(); ^ Compiling .pioenvs/mysensors_htu21d/FrameworkArduino/HardwareSerial1.cpp.o
It looks like something is still out of date. Is there anything obvious I missed or do I have to start digging ?
$EDITOR platformio.ini src/*cpp
You missed a bit of 'digging' :).
I cleaned up the code and pushed it so it will compile, but eventually you will want to dig. Blinking an led gets old.
Pull in my changes please and then it will compile for you. Then you can start with some fun.
If you like it, a possible workflow is to fork it and rename it to whatever. As you wish. I hope it helps.
@oneyb Thanks, but Platformio was a bit too complex for me too. I prefer the Arduino IDE. It's designed to make Arduino sketches, and nothing else.
Especially for education it's undefeated I think. It's the same with Processing - a great first step after working with Scratch.
If anything, I'd like the interface to be even simpler.
That's why I'm hoping to use this CLI to create a web-based tool that can flash simple sketches.
artag last edited by artag
@oneyb Thanks - that works for me now.
It does complain (of course) that it couldn't open /dev/ttyUSB0.
Is there a better way to deal with local specifics like this ? Maybe a convention of named links to specific ports that might exist ? So I could
ln -s ~/.platformio/local/serial/Uno /dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_95335343136351D0D1E0-if00
oneyb last edited by
That's funny. I can't stand the Arduino IDE for the same reason. I have to remember where to get a dependency from which menu, select the correct port, and deal with a different editor than I am used to. I also didn't like how it would doctor the code with function declarations etc. It's C++. Why hide that fact? Sure, beginner-friendly is nice and it helped me for blinking LEDs, but afterwards it was annoying. Now I am pretty fast when working with a new board.
CLI to create a web-based tool that can flash simple sketches.
That sounds a little funny. So you want to have your web browser (indirectly) accessing hardware ports or at least determining the correct port? I guess that would be ok. I have a bunch of extensions which may not be so secure. I guess for beginners that would be nice. How would you deal with library dependencies? I guess the CLI tool would be advanced enough for that.
If you are used to python the CLI from platformio is pretty simple. I guess my approach is for those who write code for a significant portion of their day.
@artag I don't know how to do that generally.
A quick look at the results of:
pio device list
will get you the information to insert into platformio.ini. Their doc is pretty good. Maybe try it to the serial id. I haven't gotten so advanced yet. They have some nice examples.
I just got this to work. It's great!
I've updated the first post with a longer guide.