Tag: Arduino

  • Making Stephen Wright’s Light Switch with the Adafruit Huzzah!

    23439940833_31be1e9c50_o

     

    Things are Different

    In 2012 I was struggling to put together a stm32 based wireless datalogger using leaflabs libmaple and a $20 wifi module. I had to write most of the code myself because libmaple was based on arduino-0022 and most of the wifi libraries made extensive use of the new classes available after arduino 1.xx (String for instance). It was painful and in the end the project was a complete failure except that I had a premade platform to make an art piece called Stephen Wrights Light Switch.

     

    8346730548_dede0fa72e_n img_0935_23439975343_o

    Nowadays you can get an Arduino capable wifi module for less than 10 bucks.

    Huzzah!

    (look it up on the internets!)


    /*-----------------------------------StephenWrightsLightSwitch.ino
     This is a hack of the provided WifiClient example.
     This is free software (BSD License)
     (C) Donald Delmar Davis , SuspectDevices.
    
     ---------------------------------------------------------------*/
    
    
    #include <ESP8266WiFi.h>
    
    
    #define SWITCH_OFF 1
    #define SWITCH_ON 0
    #define LED_OFF 0
    #define LED_ON 1
    
    
    const char* ssid = "MYWIFI";
    const char* password = "MYSECRET";
    const char* host = "www.suspectdevices.com";
    const int httpPort = 80;
    
    const char* offstate = "OFF";
    const char* onstate = "ON";
    
    #ifdef ESP8266_DEV_BOARD
    const int switchPin = 4;
    const int ledPin = 5;
    #else
    const int switchPin = 4;
    const int ledPin = 5;
    #endif 
    /*
     global variables
    */
    
    bool newSwitchValueFlag = false;
    bool oldSwitchValue = SWITCH_OFF;
    bool lightValue = SWITCH_OFF;
    
    
    /*---------------------------------------------------setup()
    
    */
    void setup() {
     bool flipFlop = SWITCH_OFF;
    
     Serial.begin(115200);
     pinMode(switchPin, INPUT_PULLUP);
     pinMode(ledPin, OUTPUT);
     digitalWrite(ledPin, LED_ON);
     delay(10);
    
     // We start by connecting to a WiFi network
    
     Serial.println();
     Serial.println();
     Serial.print("Connecting to ");
     Serial.println(ssid);
     WiFi.begin(ssid, password);
    
     while (WiFi.status() != WL_CONNECTED) {
     flipFlop = !flipFlop;
     digitalWrite(switchPin, flipFlop);
     delay(500);
     Serial.print(".");
     }
    
     digitalWrite(ledPin, LED_OFF);
    
     Serial.println("");
     Serial.println("WiFi connected");
     Serial.println("IP address: ");
     Serial.println(WiFi.localIP());
    
    }
    
    /*-------------------------------------------------------------------------loop()
    
    */
    void loop() {
     
     bool newSwitchValue;
     
     newSwitchValue = (digitalRead(switchPin)==SWITCH_ON);
     
     Serial.print("Switch="); Serial.println(newSwitchValue?"ON":"OFF");
     
     if (newSwitchValue != oldSwitchValue) {
     newSwitchValueFlag = true;
     } else {
     newSwitchValueFlag = false;
     }
     
     Serial.print("connecting to ");
     Serial.println(host);
    
     // Use WiFiClient class to create TCP connections
     WiFiClient client;
     if (!client.connect(host, httpPort)) {
     Serial.println("connection failed");
     return;
     }
    
     // We now create a URI for the request
     String url = "/art2013/settheswitch/";
     if (newSwitchValueFlag) {
     url += "?state=";
     url += newSwitchValue ? onstate : offstate;
     oldSwitchValue=newSwitchValue;
     }
    
     Serial.print("Requesting URL: ");
     Serial.println(url);
    
     // This will send the request to the server
     client.print(String("GET ") + url + " HTTP/1.1\r\n" +
     "Host: " + host + "\r\n" +
     "Connection: close\r\n\r\n");
     
     for (int t = 8; t > 0 && !client.available(); t--)
     delay(100);
    
     // Read all the lines of the reply from server and print them to Serial
     while (client.available()) {
     String line = client.readStringUntil('\r');
     if (line.lastIndexOf("ON") >= 0) {
     Serial.println("FOUND AN ON!!!");
     lightValue = SWITCH_ON;
     } else {
     lightValue = SWITCH_OFF;
     }
    
     Serial.print(line);
     }
    
     digitalWrite(ledPin, lightValue ? LED_ON : LED_OFF);
    
     Serial.println();
     Serial.println("closing connection");
     // client.close();
    
    }
    
    
  • Running Paul Stoffregons’s teensy_serial arduino core on DFU based chips.

    das blinkin
    das blinkin

    With a lot of my projects I have done my prototyping with Paul Stoffregon’s Teensy series of boards before moving them onto their own codebases. On those occasions where the “prototype was all I needed” I would compile the code using the teensyduino and then manually load the .hex file onto the target. As I am looking at using the arduino for more projects I decided to take a look at how paul interacts with the Arduino IDE and see if I could load code directly onto my chips.

    boards.txt

    The arduino allows for different chips and configurations through the boards.txt and the programmers.txt files. Each configuration usually will also have a “core” which maps the pins and handles the particulars of that chip. When you run paul’s teensyduino installer it adds several entrys to the boards.txt file including the entry below.

    teensy_ser.name=Teensy 1.0 (USB Serial)
    teensy_ser.upload.protocol=halfkay
    teensy_ser.upload.maximum_size=15872
    teensy_ser.upload.speed=38400
    teensy_ser.upload.disable_flushing=true
    teensy_ser.upload.avrdude_wrapper=teensy_reboot
    teensy_ser.build.mcu=at90usb162
    teensy_ser.build.f_cpu=16000000L
    teensy_ser.build.core=teensy_serial
    teensy_ser.build.post_compile_script=teensy_post_compile
    teensy_ser.name=Teensy 1.0 (USB Serial)
    teensy_ser.upload.protocol=halfkay
    teensy_ser.upload.maximum_size=15872
    teensy_ser.upload.speed=38400
    teensy_ser.upload.disable_flushing=true
    teensy_ser.upload.avrdude_wrapper=teensy_reboot
    teensy_ser.build.mcu=at90usb162
    teensy_ser.build.f_cpu=16000000L
    teensy_ser.build.core=teensy_serial
    ...
    Looking at pauls additions to the boards.txt I see that he is using the teensy_serial core  that he has written to create a simple usb to serial interface and to map the usb avr pins and other peripherals to the arduino conventions. He is also adds an entry to the arduino uploader class which lets him use a wrapper for avrdude which lets him use his proprietary bootloader. This wrapper is installed by the Paul’s installer and  lives in the Arduino’s bin directory. After looking to see if this wrapper was a script I replaced the entry in the boards.txt and put a script into the bin directory called “dfume”, after seeing that my replacement wrapper worked I added two new entries for each class of avr that I wanted to use the atmega32u2 and the atmega32u4
    #############################################################
    fouryou.name = atMega32U4
    fouryou.upload.protocol=atmega32u4<
    fouryou.upload.maximum_size=32256
    fouryou.upload.speed=38400
    fouryou.upload.disable_flushing=true
    fouryou.upload.avrdude_wrapper=dfume
    fouryou.build.mcu=atmega32u4
    fouryou.build.f_cpu=16000000L
    fouryou.build.core=teensy_serial
    #############################################################
    tooyou.name = atMega32u2
    tooyou.upload.protocol=atmega32u2
    tooyou.upload.maximum_size=32256
    tooyou.upload.speed=38400
    tooyou.upload.disable_flushing=true
    tooyou.upload.avrdude_wrapper=dfume
    tooyou.build.mcu=at90usb162
    tooyou.build.f_cpu=16000000L
    tooyou.build.core=teensy_serial
    #############################################################
    
    fouryou.name = atMega32U4
    fouryou.upload.protocol=atmega32u4
    fouryou.upload.maximum_size=32256
    fouryou.upload.speed=38400
    fouryou.upload.disable_flushing=true
    fouryou.upload.avrdude_wrapper=dfume
    fouryou.build.mcu=atmega32u4
    fouryou.build.f_cpu=16000000L
    fouryou.build.core=teensy_serial
    
    #############################################################
    
    tooyou.name = atMega32u2
    tooyou.upload.protocol=atmega32u2
    tooyou.upload.maximum_size=32256
    tooyou.upload.speed=38400
    tooyou.upload.disable_flushing=true
    tooyou.upload.avrdude_wrapper=dfume
    tooyou.build.mcu=at90usb162
    tooyou.build.f_cpu=16000000L
    tooyou.build.core=teensy_serial
    

    I started with a blank script that just printed the arguments passed to the wrapper and then called it by restarting my Arduino (to reload the boards.txt) And then selecting one of the new boards and “Uploading” my code. This gave me a window to interactively work through my script. Since the avrdude_wrapper code just pretends to be an avrdude most of the script is munging the arguments passed to avrdude to get the commands to pass to dfu-programmer.

    #!/usr/bin/perl
    use Getopt::Std;
    print @ARGV;
    my %args;
    my $hexfile;
    my $dfu = "/usr/local/bin/dfu-programmer";
    my $cpu;
    my $hexfile;
    
    getopt('pUc',%args);
    $hexfile=$args{U};
    $hexfile =~ s/flash:w://;
    $hexfile =~ s/:i//;
    $cpu=$args{c};
    
    print "n[" . $hexfile . "]";
    print "n[" . $cpu . "]n";
    print "$dfu $cpu erasen";
    system "$dfu $cpu erase";
    print "$dfu $cpu flash $hexfilen";
    system"$dfu $cpu flash $hexfile";
    print "$dfu $cpu startn";
    system "$dfu $cpu start 1>&2";
    print "n";
     

    There is one tricky bit. The current avr-gcc doesnt support the atmega32u2 correctly but the code for the at90usb162 is binary compatible so the build.mcu is set to the at90usb162. But then dfu-programmer supports the correct chip and wont find the device so we use the fact that the upload.protocol argument is passed directlyalong using the -c argument and everything works fine.

    So now we just use the hwb and reset buttons to get the system into dfu mode and upload our code directly from the arduino. Its not as slick as the teensy in “auto” mode but it works.

  • Day 1: Thing 1: Midi Monster Board Design

    This month we have two workshops. One on interfacing Purdata with the outside world and one on programming midi devices. I designed one board that should work for both classes.

    I will blog a bit more about this technically later at dorkbotpdx.org/feurig but that was my thing for the day.

  • Benito#7 The next big thing.

    There were a few lessons that I learned at the Arduino Cult induction workshop that I put together this month. One of which was that I needed to simplify my programmer design on the cable end and not wait until I had a full blown product. Revisiting the original I first revised the ftdi boards to use a pinout compatible with the programming end of the rbba. Then I went back to the AT90USB162 based programmer modified the schematic to reduce the parts count.

    Then I made it fit into a similar profile.

    Then I put together a parts manifest at q25 and found that in spite of the increased parts count it is actually cheaper than the ftdi boards.

    Index Quantity Part Number Description Customer Reference Backorder Quantity Unit Price
    USD Extended Price
    USD
    1 50 RHM10KARCT-ND RES 10K OHM 1/8W 5% 0805 SMD 0 0.02340 $1.17
    2 25 AT90USB162-16AURCT-ND IC AVR MCU 16K FLASH 32TQFP 0 3.15000 $78.75
    3 25 631-1099-ND CRYSTAL 8.0 MHZ SERIES 0 0.48900 $12.23
    4 30 PCC220CNCT-ND CAP 22PF 50V CERM CHIP 0805 SMD 0 0.06900 $2.07
    5 200 RHM220ACT-ND RES 220 OHM 1/8W 5% 0805 SMD 0 0.02340 $4.68
    6 50 RHM22ACT-ND RES 22 OHM 1/8W 5% 0805 SMD 0 0.04080 $2.04
    7 100 399-1168-1-ND CAP .10UF 25V CERAMIC X7R 0805 0 0.02670 $2.67
    8 50 399-1284-1-ND CAP 1.0UF 16V CERAMIC X7R 0805 0 0.09500 $4.75
    9 30 475-1401-ND LED 3MM 570NM GREEN DIFF RADIAL 0 0.05600 $1.68
    10 1 AT43301-SU-ND IC USB HUB CTRLR 4PORT 24SOIC 0 1.83000 $1.83
    11 25 609-1039-ND CONN RCPT USB TYPE B R/A PCB 0 0.54200 $13.55
    Subtotal $125.42

  • A single sided ft232rl based arduino programming board.

    I was so happy with the boards I did the other day that I decided to make some small boards for the ft232 so that aidan would have a programmer for his breadboard RBBA. I made 20 of these boards .

    QTY Supplier Part number description cost
    1 DIGIKEY 604-00043-ND IC FTDI FT232RL USB-SRL 28-SSOP 4.02
    1 DIGIKEY 151-1121-ND CONN USB JACK TYPE B HORIZON R/A .85
    1 DIGIKEY 490-1035-1-ND FERRITE CHIP 30 OHM 1000MA 0603 .06
    3 DIGIKEY 399-1169-1-ND CAP .10UF 50V CERAMIC X7R 0805 .15
    2 DIGIKEY RHM220ARCT-ND RES 220 OHM 1/8W 5% 0805 SMD .07
    2 DIGIKEY 475-1400-ND LED 3MM 570NM GREEN CLR RADIAL .12


    Link to board image at 600%
     

  • Arduino Programmer

    This was started at http://www.thing-a-day.com/2008/02/04/day-4-thing-4-aduino-adaboot-programmer/My Bulky Prototype

    It is part of the way that I do programming on the avr platform and the Arduino.

    I was using the programming half of a a bulky prototype that I have been working on to program an RBBa based maze solving mouse and I looked at the pile hanging precariously off of the coffee table and thought to myself.

    “I need to just build one of these. “

    The finished product
    Modifying Sparkfun Board. to fit in the box the input side
    flea assembly blinkin lights in place
    test run Translucence done  

    So I did.

    The programmer is based on the Auto-Reset Hack and the AdaBoot bootloader. The reset is pulled by putting a capacitor on the DTR line of the serial interface which is also the bootloader interface. Most people put the cap on the Arduino but I put it on the programmer (where it belongs). This programmer was built using the ftdi ft232rl breakout board sold by sparkfun. I had to trim it down to get it to fit in the pretty blue box i bought at Tap Plastics. The chip out of the box presents two of its 4 gpio (general pourpose i/o) pins to indicate when serial is being sent and recieved. I wired a pair of very bright leds that I had to them and then tried to pipe the light to the corners using some translucent plastic tubes and hot glue. It looks pretty cool!

  • The $15 Wiring Board

    This was started out as one of my things for Thing-A-Day (2008) (http://www.thing-a-day.com/2008/02/22/day-22-thing-22-the-15-wiring-board/)

    This follows my work getting the wiring software platform working on some generic mega128 boards. It is somehow related to my work on reducing the costs of the Arduino runtime to less than $4

    I recently found the code for an Stk500v2 based bootloader at http://www.avride.com/article/wiring/ for the new wiring platform. I have wanted to run wiring on several of the systems I have using the mega128 and the olimex header board that sparkfun sells. Between sparkfun and Ebay my per board cost is about 11 bucks. With the ftdi ft232rl usb to serial chip at $4 that would make the wiring platform affordable :)

    My initial attempt was using Wiring 0014 which seemed pretty darned broken. It didnt take long for 0015 to come out fortunately. Once I got the bootloader to work with wiring I realized that the wiring platform requires a 32khz clock crystal to be connected to tosc1 and tosc2. On the Olimex boards there is a space for this crystal. On some other boards like the Futulec ET-AVR-stamp this had to be soldered to the legs of the processor.

    Once this was added to the boards things started working. Below you can see the Futurelec ET-AVR-STAMP running my “antisocial” wiring program.

  • Day 28: Thing 28: Charley plexed display

    (Archive of: http://www.thing-a-day2.com/2008/02/28/day-28-thing-28-charley-plexed-display/)

    Today I made the software for some hardware that I built a while ago.

    The origional question was if I got 15000 leds for next to nothing and it costs 4-15 per 8×8 array (with the 4$ solution also needing 4 to eleven additional parts) to drive them are we getting anywhere? I looked at 2 solutions before realizing that the leds were to dim to do much of anything that interested me. One solution was to drive the led rows with cmos shift registers and sink the columns using TPIC6 based shift registers.

    The other solution is called charlyplexing.

    The idea is to multiplex a series of leds in a way that maximizes the leds per io pin avaliable. The led connections are paired and driven one at a time depending on the direction of the output pins. The remaining pins are tri-stated out of the way. It is a pretty intense software complexity vs hardware problem.

    As only one led in the array is on at a given time, multiplexing the leds into an array reduces the brightness significantly making my near free leds impractical for this application. (These are 5×6 array, the fonts i used were for 5×7 displays)

  • Day 25: Thing 25: AntiSocial(ism)

    (Archive of: http://www.thing-a-day2.com/2008/02/25/day-25-thing-25-antisocialism/)

    I went to radio shack about a month ago and bought an utrasonic distance sensor made by parallax called a ping))).

    I have been feeling cranky and anti social lately so I thought I should make something that didnt want to be bothered.


    I am considering adding an air horn for people who dont respect its limits but think that the neighbors might not appreciate it much.

  • Day 24: Thing 24 — Mouse Whiskers (touch sensor)

    (Archive of: http://www.thing-a-day2.com/2008/02/24/day-24-thing-24-mouse-whiskers-touch-sensor/)

    Two weekends ago Aidan and I went to radio shack and he was looking at these $9 bug bots which have a sound sensor, two touch sensors (antennae) and 6 legs. He was very interseted in both the walking mechanism and the touch sensor. We decided that we should add one of those to his arduino based mouse (A168).