arduino

Raspberry: upload Arduino sketch from CLI

install these packages

sudo apt-get install arduino-core arduino-mk

Then add yourself to the dialout group to allow you to upload code to the Arduino board

sudo usermod -a -G dialout pi (Change pi to be your username if different)

Create Makefile

ARDUINO_DIR = /usr/share/arduino
BOARD_TAG = uno
ARDUINO_PORT = /dev/ttyACM*
ARDUINO_LIBS =
include /usr/share/arduino/Arduino.mk

to build

make

to upload

make upload

ESP8266 WiFi module

Link for add board manager

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Erase the esp

esptool.py erase_flash

Code to flash AT firmware to ESP8266 (ESP8266_AT_Bin_V1.5.1)

esptool.py --baud 115200 --port /dev/tty.wchusbserial1420 write_flash -fm dio -ff 40m -fs detect 0x00000 boot_v1.7.bin 0x01000 user1.1024.new.2.bin 0xfc000 esp_init_data_default.bin 0x7e000 blank.bin 0xfe000 blank.bin

L293D, H Bridge Arduino

L293D is a DC motor controller.

Below Arduino code to use it.

unsigned char table[128] = {0};

int motor1_A=6;
int motor1_B=5;
int motor1_Speed=3;              

void setup()
{  
  pinMode(motor1_A,OUTPUT);
  pinMode(motor1_B,OUTPUT);
}

void loop()
{
  // motor1
  for (int i=0; i<256; i+=1){
    digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
    digitalWrite(motor1_B,LOW);
    analogWrite(motor1_Speed,i); // speed counts from 0 to 255
    delay(20);
  }
  for (int i=255; i>0; i-=1){
    digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
    digitalWrite(motor1_B,LOW);
    analogWrite(motor1_Speed,i); // speed counts from 0 to 255
    delay(20);
  }
}

Arduino and Python

If you want to read Arduino serial from Python.

Install pySerial:

pip intall pyserial

the code:

import serial
...
print('# Arduino Reader - hackweb')
print('entering loop...')

ardu = serial.Serial('COM3', 115200)

time.sleep(2)

while True:

print(ardu.readline())