Files
hpos-desktop/flash.py

69 lines
1.5 KiB
Python

from everywhereml.arduino import Sketch, Ino, H
"""
Create a sketch object.
A sketch is defined by:
- a name (required)
- a folder (optional)
If you leave the folder empty, the current working directory will be used.
You can use the special name ':system:' to use the default Arduino sketches folder
(as reported by the command `arduino-cli config dump`)
"""
sketch = Sketch(name="PyDuino", folder=":system:")
"""
Then you can add files to the project (either the .ino main file or
C++ header files)
"""
sketch += Ino("""
#include "hello.h"
#include <SPI.h>
#include <Wire.h>
#include <math.h>
#include "ADS1X15.h"
void setup() {
Serial.begin(115200);
}
void loop() {
hello();
delay(1000);
}
""")
sketch += H("hello.h", """
void hello() {
Serial.println("hello smi8");
}
""")
"""
Compile sketch for Arduino Nano 33 BLE board.
The board you target must appear in the `arduino-cli board listall` command.
If you know the FQBN (Fully Qualified Board Name), you can use that too.
"""
if sketch.compile(board='arduino:avr:nano:cpu=atmega328old').is_successful:
print('Log', sketch.output)
print('Sketch stats', sketch.stats)
else:
print('ERROR', sketch.output)
"""
You can specify the exact port
"""
# sketch.upload(port='/dev/cu.usbmodem14201')
sketch.upload(port='/dev/cu.usbserial-1420')
# """
# Or even part of it.
# The library will look for the best match.
# """
# sketch.upload(port='ttyUSB')
# sketch.upload(port='/dev/cu.usbserial-1420') #/dev/cu.usbmodem
print('hi', sketch.output)