hail to the King Arduin

connecting

I got an Arduino Nano clone for ~ USD 3.5 and attempted to connect it to my OSX Yosemite laptop.

At first, no lights, my micro-USB cable was dead. Found another one and the Nano lit up.

Arduino Nano v3.0 clone

But the Arduino IDE was not seeing the board. I was only seeing the USB modem serial ports in the selection.

After various tries downloading and installing the ch34X driver, I could talk with the board, but had random kernel panics.

I finally came across this Github project with a patched version of the driver. The project says "Sierra", but I tried the advertised:

$ brew tap mengbo/ch340g-ch34g-ch34x-mac-os-x-driver https://github.com/mengbo/ch340g-ch34g-ch34x-mac-os-x-driver
$ brew cask install wch-ch34x-usb-serial-driver

and it then worked flawlessly on my Yosemite OSX, with the cu.wchusbserial1410 that appears when the Nano board is connected.

developping

The Arduino IDE is nice and all, it provides access to a wealth of libraries and example, but a Vim person like me was soon feeling slowed by the editor.

You still need the Arduino IDE around, but you can use an Arduino-Makefile to stay in the command line.

At first, I tried to work with this Makefile following in the instructions behind the link in the project description, but that was an error.

Following the project readme is the path to the success.

$ brew tap sudar/arduino-mk
$ brew install arduino-mk

$ pip install pyserial

Then I included a link to the template makefile

ARDUINO_DIR:=/Applications/Arduino.app/Contents/Java
ARDMK_DIR:=/usr/local/opt/arduino-mk
AVR_TOOLS_DIR:=$(ARDUINO_DIR)/hardware/tools/avr
MONITOR_PORT:=/dev/cu.wchusbserial1410
BOARD_TAG:=nano
BOARD_SUB:=atmega328

include /usr/local/opt/arduino-mk/Arduino.mk

I wrote my serial_blink.ino thus


const unsigned int LED_PIN = 13;
const unsigned int BAUD_RATE = 9600;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(BAUD_RATE);
}

void loop() {
  if ( ! Serial.available() > 0) return;
  int c = Serial.read();
  if (c == '0') {
    digitalWrite(LED_PIN, LOW);
  }
  else if (c == '1') {
    digitalWrite(LED_PIN, HIGH);
  }
}

and uploaded it with make upload, hit the serial console with make monitor and was able to turn the LED on with a 1 and off with a 0.

My small start project is at https://github.com/jmettraux/serial_blink.