Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Got lisp reading AND writing to the arduino. I needed to issue the pr…

…oper `stty` command before it would allow me to write without resetting

the arduino.  Also had to change the :external-format to :ascii, which makes sense.  This $30 microcontroller doesn't understand UTF-8.  Now
that the arduino is listening for serial input, I have to hit the reset button while uploading new programs to it, otherwise its program
just reads the bytes like and the avrdude programmer fails.
  • Loading branch information...
commit 17d60ace264f97f32b30db23ea9430f9aaede95f 1 parent d8e799e
@ryepup authored
Showing with 44 additions and 10 deletions.
  1. +23 −4 serial-repeater/reader.lisp
  2. +21 −6 serial-repeater/serial-repeater.pde
View
27 serial-repeater/reader.lisp
@@ -5,9 +5,28 @@
(in-package #:serial-reader)
-(defun read-serial ()
- (with-open-file (s "/dev/ttyUSB0"
- :direction :io
- :if-exists :overwrite)
+(defvar *default-serial-stream* nil "special variable to hold the default stream")
+
+(defvar *device-path* "/dev/ttyUSB0")
+
+(defun initialize (speed)
+ "configures the serial port to run at the given speed"
+ (sb-ext:run-program
+ "/bin/stty" (list "-F" *device-path* (princ-to-string speed)
+ "raw -parenb -parodd cs8 -hupcl -cstopb clocal")))
+
+(defmacro with-serial-io ((stream) &body body)
+ `(with-open-file (,stream *device-path*
+ :direction :io
+ :if-exists :overwrite
+ :external-format :ascii )
+ (let ((*default-serial-stream* ,stream))
+ ,@body)))
+
+(defun read-serial ()
+ (with-serial-io (s)
(read-line s)))
+(defun echoer (byte)
+ (with-serial-io (s)
+ (format s "~D~%" byte)))
View
27 serial-repeater/serial-repeater.pde
@@ -1,19 +1,34 @@
// -*- mode: c -*-
int ledPin = 13;
int blinkMs = 2000;
+int inByte = 0;
+int on = 0;
void setup(){
pinMode(ledPin, OUTPUT);
- Serial.begin(9600);
+ Serial.begin(19200);
}
+void blink (int times, int ms){
+ for(int i = 0; i < times; i++){
+ digitalWrite(ledPin, HIGH);
+ delay(ms);
+ digitalWrite(ledPin, LOW);
+ delay(ms);
+ }
+}
+
+
void loop (){
- digitalWrite(ledPin, HIGH);
- Serial.println("Hello");
- delay(blinkMs);
- digitalWrite(ledPin, LOW);
- delay(blinkMs);
+ if(Serial.available() > 0){
+ blink(5,250);
+ inByte = Serial.read();
+ Serial.flush();
+ }
+ blink(2,250);
+ delay(1000);
}
+
extern "C" void __cxa_pure_virtual(void);
void __cxa_pure_virtual(void) {}
Please sign in to comment.
Something went wrong with that request. Please try again.