Latest Updates: electronics RSS

  • Control stepper motors with Raspberry Pi and node.js

    Ellen 11:55 on February 25, 2014 | 5 Permalink | Reply
    Tags: electronics, motors, , , steppers

    Continuing the journey on how to control things with node.js on the Raspberry Pi I set up 2 stepper motors and controlled them in real time with Hydna. You can can read futher on how to install Hydna on Raspberry Pi here.

    stepper_motors_sundh_com

    Wire up your motors with a stepper motor driver shield. I used Easy Driver and connected it with Pololu stepper motors:
    nodejs_stepper_motor_ellen_sundh
    The to pins that controls the motors in this diagram are pin number 16(GPIO 23) and pin number 18(GPIO 24). Pin number 18 controls the direction of the motor and pin number 16 the speed. With 1K ohm resistors connected to the ground for each of these pins we connect them to the Easy driver.

    Depending on the stepper motor you have, you will need to check the bipolar stepper motor wiring diagram for your motor. The motors I used had the following diagram where A(black) and C(green) connects to the A pins and B(red) and D(blue) connects to B pins.

    0J2296.230

    Install pi-gpio and go ahead with this script to control the stepper motors:

    var gpio=require("pi-gpio");

    stopMotors = false;

    function sleep(milliseconds) {
      var start = new Date().getTime();
      for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds){
          break;
        }
      }
    }

    gpio.open(16,"output",function(err){    
      console.log("Pin 16 open"); // Opens pin 16 as output  
    });

    gpio.open(18,"output",function(err){    
      console.log("Pin 18 open"); // Opens pin 18 as output  
    });

    // Runs motor in the set direction
    function move() {
       gpio.write(16, 1, function() {
            sleep(1000);  
             gpio.write(16, 0, function() {
                sleep(1000);
                if(!stopMotors)move();
            });      
          });
    }

    function stopMotor() {
      stopMotors = true;
    }

    // Changing direction of motor
    function left() {
      stopMotors = false;
      gpio.write(18, 1, function() {
          move();
      });  
    }

    // Changing direction of motor
    function right() {
      stopMotors = false;
      gpio.write(18, 0, function() {
          move();
      });  
    }

  • Realtime control of GPIO:s with Hydna

    Ellen 12:33 on February 13, 2014 | 0 Permalink | Reply
    Tags: electronics, gpio, , , , realtime

    raspberry_pi_nodejs_hydna

    Want to control the pins on you Raspberry Pi in real time? With the scaleable realtime platform from Hydna you can set how many that can access the GPIOs and when. Install the node modules gpio and hydna to controll your GPIO:s over the net.

    Install node.js

    sudo apt-get upgrade;
    sudo apt-get update
    sudo apt-get install nodejs npm node-semver
    npm config set registry http://registry.npmjs.org/

    Open the profile file with:

    sudo nano /etc/profile

    And enter the following:

    NODE_JS_HOME=/usr/bin/nodejs
    PATH=$PATH:$NODE_JS_HOME/bin

    NOTE! Log out and then in again in order to make the changes go through.

    To run nodejs with with the command node, link them to with:

    sudo ln -s /usr/bin/nodejs /usr/bin/node

    Make sure to check where your node was installed and add it to NODE_JS_HOME

    Install GPIO

    npm install pi-gpio

    Install GPIO-ADMIN

    cd /home/pi
    sudo git clone git://github.com/quick2wire/quick2wire-gpio-admin.git
    cd quick2wire-gpio-admin
    sudo make
    sudo make install
    sudo adduser pi gpio

    Try out gpio-admin with the following line:

    gpio-admin export 22

    If you get this error

    Error /bin/sh: 1: gpio-admin: Permission denied

    follow these steps:

    sudo groupadd gpio
    sudo usermod -aG gpio
    su
    sudo chgrp gpio /sys/class/gpio/export
    sudo chgrp gpio /sys/class/gpio/unexport
    sudo chmod 775 /sys/class/gpio/export
    sudo chmod 775 /sys/class/gpio/unexport

    Install Hydna

    npm install hydna

    With Hydna you can send real time messages to your pi and allow a certain number of clients to connect to your Raspberry Pi. With Hydna’s Behaviours you set the behaviours of your different channels.

    The following example code shows how to control your gpios with messages from Hydna:

    var gpio=require("pi-gpio"); // Include the pi-gpio library to control the gpios
    gpio.open(12,"output",function(err){
    console.log("Pin open"); // Opens pin 12 as output
    });
    var hydna = require(‘hydna’);
    // Open channel in "read/write" mode. All data sent to channel will
    // loop back from the remote connection.
    var channel = hydna.createChannel(‘domainname.hydna.net/rpi’, ‘readwrite’);
    // Connect handler, is triggered once that the channel is connected
    channel.on(‘connect’, function () {
    this.write(‘Status: ok’);
    });
    // Data handler, is triggered each time DATA is received on the channel
    channel.on(‘data’, function (data) {
     
    // Log data received on channel.
    console.log(data);
    if(data == "on") {
    gpio.write(12, 1, function() {
    });
    } else if(data == "off") {
    gpio.write(12, 0, function() {
    });
    } else if(data == "end") {
    gpio.close(12); // Close pin
    this.end(); //Close the channel, which terminates the underlying receive-loop.
    }
    });

  • Connect Parallax RFID to Raspberry Pi

    Ellen 15:01 on September 18, 2013 | 2 Permalink | Reply
    Tags: , electronics,

    parallax_rfid_reader

    To connect a Parallax RFID Reader to the Raspberry Pi you can either use the USB version of the Parallax RFID reader or the pin enabled used in this example. With the pin enabled Parallax version the data is sent to the Raspberry pi serial pins with the pins TXD and RXD pins. With the RFID reader with only need to use RXD as we will only receive data from the RFID reader.

    Wiring setup

    The RFID reader operates on 5V but the Raspberry Pi GPIOs operate on 3.3 V which mean that in order to read the serial data we need to convert it from high volt to low volt. There is circuit available from Sparkfun doing just that. It is called Logic Level Converter and will be part of the wiring between the Raspberry Pi and the RFID reader.

    Below is the schematics for the connections you need to make.

    1. Connect your common ground to both ends of the Logic Level Converter and RFID reader. Note that the Parallax RFID reader needs the Enable pin to be connected to ground in order to read RFID tags. When the LED on the RFID reader turns red it means that it is ready to read. (Black)

    2. Connect the high volt  from 5V pin to HV pin. (Red)

    3. Connect the low volt from 3.3 V pin to LV pin. (Orange)

    4. Connect the SOUT pin to  serial input RXI on the Logic Level Converter. (Blue)

    5. Connect the seriel output RXO to the pin RXD on the Raspberry Pi.

    Screen Shot 2013-09-18 at 3.07.29 PM

    Enable serial port

    To make the serial port available for your own use you need to edit the file /etc/inittab.

    sudo nano /etc/inittab

    Comment out the following line in inittab

    T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

    Like this:

    #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

    Install minicom for testing

    To read and test your tags on the Raspberry Pi you need a set of packages:
    A great package to test your serial port is to install minicom:

    sudo apt-get install minicom

    To test your serial port you can use mimicom command like this:

    minicom -b 115200 -o -D /dev/ttyAMA0

    Read RFID tags with Python

    To access the serial port from Python install the pySerial package with command line:

    sudo apt-get install python-serial

    Now you can import the serial library on order to access the serial data sent to the Raspberry Pi from the serial port. Note that you can set the timeout of the RFID reader to make the read timeout after a while. The example code below times out the serial read after half a second. This can be useful to set a longer or shorter timeout depending on if you execute other things in your loop or application.

    import serial
    ser = serial.Serial(‘/dev/ttyAMA0′, 2400, timeout=0.5)
    while True:
        string = ser.read(12)  
        if len(string) != 0:
            print string

    Raspberry Pi Lab posted a great Python script on how to check which tag is read in the rfid-test2.py.

  • Heavy duty pull sensors

    Ellen 18:21 on June 25, 2012 | 0 Permalink | Reply
    Tags: , electronics, ,

    Interacting with installations with a long life time we turn to heavy duty sensors that can handle a lot of cycles. The string and pull sensors below can handle more than a million cycles and are built for industrial use. They can also be connected to circuit board like Arduino.

    Check out all the pull sensors and string pots from Celesco. Novotechnik also offers a wide range of pull sensors.

    Check out this Processing and Arduino project by nhw3030 with Celesco string sensors.

  • Unity + Processing + Arduino

    Ellen 10:32 on May 31, 2012 | 17 Permalink | Reply
    Tags: , electronics, , ,

    I did a test connecting Arduino and Unity with the help of Processing and a Open Sound Control library. When I am pushing the Flexi Force sensor the values affect a cube within Unity. To get this setup do the following:

    Arduino
    Load the Standard Firmdata on to your Arduino. Check out a full Arduino + Processing tutorial to get the setup.

    Processing
    Download the oscP5 processing library and put it in your Processing sketch folder in the folder libraries.

    Initialize oscP5 library and broadcast data to port 12000. The port Unity will listen to.
    Add the remote location to listen to on port 3200. If Unity would broadcast event in this example, the broadcast port would be set to 3200. Initialise Arduino to be used later on.

    oscP5 = new OscP5(this,12000);
      myRemoteLocation = new NetAddress("127.0.0.1",3200);
      arduino = new Arduino(this, Arduino.list()[0], 57600);

    In the draw function we read the analoge pin 0 to get sensor values from the Flexi Force sensor. Set the OSC message to flexiforce. Unity will listen to this label. Add the message of the sensor value into the osc message with add method. This method can take numbers, strings and byte data.

    float flexiforceSensor = arduino.analogRead(0);
    OscMessage oscMess = new OscMessage("/flexiforce");
    oscMess.add(flexiforceSensor);

    oscP5.send(oscMess, myRemoteLocation);

    The entire Processing sketch can be seen here.

    Unity
    In Unity you can import the Osc.cs and UDPPacketIO.cs to broadcast and listen to UDP data.

    Set up the corresponding host and ports in your Unity script.

    public var OSCHost : String = "127.0.0.1";
    public var SendToPort : int = 3200;
    public var ListenerPort : int = 12000;

    Import the UDPPacketIO and Osc components and feed in the host and ports. Add your specific label of your osc message and what method to call when receiving this event from Processing.

    var udp : UDPPacketIO = GetComponent("UDPPacketIO");
    udp.init(OSCHost, SendToPort, ListenerPort);
           
    handler = GetComponent("Osc");
    handler.init(udp);
    handler.SetAddressHandler("/flexiforce", AffectObject);

    In the receiving method you can print out the label and message values. In this case the sensor value from the Flexi Force. The cube will change width when getting a new value from Processing.

    public function AffectObject(oscMessage : OscMessage) : void
    {      
            Debug.Log("Event name: " + Osc.OscMessageToString(oscMessage));
            Debug.Log("Event data: " + oscMessage.Values[0]);
           
            var myCube = GameObject.Find("Cube");
            var boxWidth:int = 8 - ( oscMessage.Values[0]);
            myCube.transform.localScale = Vector3(boxWidth,5,5);
    }

  • Geek Girl Meetup in London

    Ellen 15:33 on April 29, 2012 | 0 Permalink | Reply
    Tags: electronics, Geek Girl Meetup 2012, geekgirl,

    Spending the day at Geek Girl Meetup in London. Talked about The Sound of Football and my Arduino projects.

    In the Arduino session I presented my Depressed Shoe Shelf, the bend sensing belt Bad Posture, how to control electronics from the internet using Processing.

    google_campus_society46_680

  • Arduino library for LED Message Display

    Ellen 18:53 on April 15, 2012 | 13 Permalink | Reply
    Tags: , Arduino library, electronics, LED

    Making life a lot easier I wrote an Arduino library that takes care of converting strings and calculating the checksum of all commands sent to the LED Message Display. Compared to the first example of sending text to the display the library can send commands of how long the text should display, how to be animated in and out and display European characters. All included in the BockiMessageBoard library on Github.

    amplus_led_message_display_sundh

    The code below shows how to initiate and send messages:

    #include <BockiMessageBoard.h>

    BockiMessageBoard messageBoard = BockiMessageBoard(0); // 0 is the Id of your message board

    void setup {
          // Configure the display before sending the text.
          int displayTime = 0.5; // Input 0.5 sec or 1 to 25 seconds
          messageBoard.configure(displayTime,SCROLLLEFT,VERTICALCLOSE);
    }

    void loop {
          String euroChars = "Testing with European characters <U45><U44><U76><U65><U64><U61>";
          messageBoard.displayMessage(PAGE_A,euroChars);
    }

    The library generate serial data to the LED Message Display with this setup:

    <ID00><L1><PA><FE><MA><WC><FD>MESSAGE CHECKSUM<E>

    <ID00> - The id of the message board.
    <L1> - Line number
    <PA> - Page id
    <FE> - How the text will appear. Scrolling, twinkeling, snowing…
    <MA> -
    <WC> - Waiting time. How long to display text.
    <FD> - How the text will disappear. Scrolling, twinkeling, snowing…
    MESSAGE - The message text to be displayed
    CHECKSUM - Hex value calculated on all tag sabove.
    <E> - End of data.

    The circuit uses a RJ14 cable to transfer the serial data to the display board:
    ethernet_led_bb

  • Make WiShield work in latest Arduino IDE

    Ellen 17:22 on February 17, 2012 | 28 Permalink | Reply
    Tags: , electronics, wishield

    1. Download the WiShield library that has been optimized and fixed by users:

    2. Rename the folder to WiShield and put it into Arduino_sketch_folder/libraries
    You might notice that just running a sketch with the WiShield library will generate errors like:

    return type specified for ‘virtual void Server::write(uint8_t)’
    clock-arch.c:44:20: error: wiring.h: No such file or directory

    3. In order to get rid of these error you need to change the corresponding names in the following files:

    clock-arch.c
    Replace #include “wiring.h” with #include “Arduino.h”

    WiShield.cpp
    Replace #include “WProgram.h” to #include “Arduino.h”

    WiServer.cpp
    Replace #include “WProgram.h” to #include “Arduino.h”
    Replace void Server::write(uint8_t.. to be size_t Server::write(uint8_t..

    WiServer.h
    Replace virtual void write(uint8_t); to virtual size_t write(uint8_t);

  • Get analog value from Yellow Jacket

    Ellen 22:07 on February 14, 2012 | 1 Permalink | Reply
    Tags: Asynclabs, electronics, Rugged Circuits,

    rugged_circuitThe Yellow Jacket wifi microcontroller originally from Asynclabs is being produced by The Rugged Circuits. I got one and here is a tutorial on how to read an analogue value from the board.

    The Yellow Jacket is using the library WiShield from Asynclabs. I have seen a lot of puzzled comments on how to get it working. Just running one of the WiShield examples in the latest Arduino IDE gave me a few errors:

    “error: conflicting return type specified for ‘virtual void Server::write(uint8_t)’”

    It seems like the WiShield library isn’t really up to sync with the latest Arduino IDE. So I used the older Arduino IDE and downloaded the WiShield 1.3.0 library which is made for the older Arduino 0022.

    Your network settings
    Next thing I modified the example SimpleClient with my personal network settings. The local ip is the address where I will be able to access the board from and with that the sensor value of the analog input. In your network settings you can see what type of security settings your network has. Change the digit in code to correspond to your network’s security type. In my case I have got a WPA2 password that I enter in the code.

    unsigned char local_ip[] = {192,168,2,240};     // I choose a free IP address in my network
    unsigned char gateway_ip[] = {192,168,2,1}; // Address of my router
    unsigned char subnet_mask[] = {255,255,255,0};
    const prog_char ssid[] PROGMEM = {"NAME_OF_MY_WIFI_NETWORK"};
    unsigned char security_type = 3;        // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2
    // WPA/WPA2 passphrase
    const prog_char security_passphrase[] PROGMEM = {"my_password"};

    Initializing WiServer
    In the setup method of the sketch the WiServer is initialized together with the name of a function defining what we will see when surfing into the board.

    void setup() {
    WiServer.init(sendMyPage);
    WiServer.enableVerboseMode(true);
    }

    Serving data to web page
    As in any Arduino sketch the analog value can be reached through analogRead. Within the method sendMyPage the content of the web page is printed together with the sensor value.

    With WiServer.print we serve the value to

    WiServer.print("");
    sensorValue = analogRead(sensorPin);
    WiServer.print("sensorValue :");
    WiServer.print(sensorValue);
    WiServer.print("");

    Good to know-list
    Good to know when uploading your code to the board:

    • You need to set your board type to Arduino Uno.
    • It will take about 30 seconds for the Yellow Jacket to start up after uploading the code or adding power to it.
    • You can source the Yellow Jacket with its own power by adding 7V-24VDC to pin raw.
    • Depending on which code library you want to use you need to activate it in apps-conf.h within the WiServer library code. In this example I have uncommented #define APP_WISERVER

  • Small Ehternet access just got smaller

    Ellen 22:08 on January 12, 2012 | 0 Permalink | Reply
    Tags: , arduino shield, electronics, ethernet, freetronics

    ethernet

    The Arduino Ethernet shield has been around for some time now. It’s a great solution for cutting out the middle man of the computer when check things online from the Arduino. In order to build smaller cases I stumbled upon EtherTen from Freetronics. It’s a fully Arduino-compatible board that runs Arduino code AND connects to internet with Ethernet.

    Lets make a list of the pros:
    - Smaller than Arduino board with Ethernet shield on top
    - Runs Arduino Ethernet library
    - Power of Ethernet, no power supply needed (!!!!)
    - Micro SD card holder
    - And sexy round corners (rounder than the Ethernet Shield)
    - Neat mini USB socket

    When it arrived I simply ran the TwitterClient file by Tom Igoe in Ethernet examples of the Arduino IDE and it was up and running. To call my custom php file was a bit harder though. Example code to be posted on my Arduino Circuit Blog shortly.

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
esc
cancel