Serial Port Mini RS232 to TTL Converter Adaptor Module Board MAX3232 with Arduino

So I buy 5 of these little things when I find out I am dealing with RS232 device instead of a TTL device.  They arrive quick and I am delighted only to find I dont quite know how to wire them up.  The project is to use an Arduino – which I love dearly – to drive an LED rolling display. I am not an electronics expert – so I struggled a little and popped 2 of them good and proper..

Never mind.  I’ll buy this instead http://www.ebay.co.uk/itm/RS232-Serial-Port-to-TTL-Converter-Module-Board-MAX232-for-PIC-ATMEL-MCU-5V-/260995809488?pt=UK_Computing_Other_Computing_Networking&hash=item3cc49000d0

I am as always standing on the shoulders of giants – http://www.sundh.com/blog/2012/04/arduino-library-for-led-message-display/comment-page-1/#comment-93629

T2k60XXmhOXXXXXXXX_!!12774208

So my experience is:

From the RS232 Port – RX, TX and GND.  Thats the -> -<and the – signs.  Easy enough

– GND

-> RX

<- TX

On the TTL (Arduino)  side – DO NOT USE 5V use 3.3V as this toasts the device and heats up and like tops itself.  It certainly got very toasty when I put 5V across it.  This could be because I messed up somewhere in the wiring but it certainly works well for me.  I can also use the SoftwareSerial library as well so I don’t need to use TX/RX on the TTL Serial pins 0 and 1

So TTL is

– GND

-> – PIN X

<- PIN Y

For my device I used PIN 0 and PIN 1 – TX/RX – but I guess you can use other pins.

TTL RS232 Pinouts

TTL RS232 Pinouts

 

 

Hope this helps – it does work!

Updated RoboSapien IR Control – Arduino

There is a brilliant hack for these http://playground.arduino.cc/Main/RoboSapienIR.  I wired this up – but I ended cutting up the poor thing – so I thought I could try it with an IR transmitter instead to do the same thing.  Also means you dont have to ruin your soldering iron punching a hole through the body 🙂

I decided to use the Ken Shirriff IR library.  Its  work of genius.

http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html

But it didnt have one for Robosapien. The way it works is pretty cool – but you need a couple of days hack time to figure it out.  The codes from the sapien controller seemed to be in single bytes – so with some effort I managed to get it to transmit those codes.  I tried it on 6 sapiens I bought for a school project.

I updated three of the library files.  I have not included the whole library – just the updated files – so best way is to downloaded Ken’s library and then just replace with these files here

You’ll need an IR Transmitter with an Arduino board.  Something like this http://emartee.com/product/42200/  This project looks like the sort of thing you want to do: http://jerrylparker.com/?p=94

Wire it up with Pin 3 and make sure you hold the transmitter close to the Robots head.  These arduino ones dont have much power and I found the transmitter needed to be within 10-15cm.  However the idea is to be able to replace the onboard controller with Arduino – so you can still do that and without hacking up the toy.

I mapped out the buttons to codes – so in the Arduino sketch – use commands like  irsend.sendRSV1(142);  The sketch is at the bottom.  Its pretty simple.  I had done two types – ones where you have a set sequence.  The other was to initiate the sequence from a PC.  Hence the Serial.read().  I use Processing for that stuff – its amazing as well.

This was done in Excel – which you can download here.  This is the simple pasted version.

 

Button Controller Function Presses Arduino Code
12 Red Turn Right 1 128
1 Red Right Arm Up 2 129
4 Red Right Arm Out 2 130
5 Red Tilt Body right 1 131
2 Red Right Arm Down 2 132
3 Red Right Arm In 2 133
11 Red Walk Forward 2 134
15 Red Walk Backwards 2 135
14 Red Turn Left 1 136
6 Red Left Arm Up 2 137
9 Red Left Arm Out 2 138
10 Red Tilt Body Right 1 139
7 Red Left Arm Down 2 140
8 Red Left Arm In 2 141
13 Red Stop 1 142
19 Red Master Command Program 1 144
20 Red Program Play 1 145
16 Red Right Sensor Program 1 146
18 Red Left Sensor Program 1 147
17 Red Sonic Sensor Program 1 148
12 Green Right Turn Step 1 160
1 Green Right Hand Thump 1 161
4 Green Right Hand Throw 1 162
5 Green Sleep 1 163
2 Green Right Hand Pickup 1 164
3 Green Lean Backward 1 165
11 Green Forward Step 1 166
15 Green Backward Step 1 167
14 Green Left Turn Step 1 168
6 Green Left Hand thump 1 169
9 Green Left hand Throw 1 170
10 Green Listen 1 171
7 Green Left Hand Pickup 1 172
8 Green Lean Forward 1 173
13 Green Reset 1 174
19 Green Master Command Program 1 176
20 Green Wake Up 1 177
16 Green Right Sensor Program Execute 1 178
18 Green Left Sensor Program Execute 1 179
17 Green Sonic Sensor Program Execute 1 180
12 Orange Right Hand Strike 3 1 192
1 Orange Right Hand Sweep 1 193
4 Orange Burp 1 194
5 Orange Right Hand Strike 1 195
2 Orange High 5 1 196
3 Orange Right Hand Strike 1 197
11 Orange Bulldozer 1 198
15 Orange Oops 1 199
14 Orange Left Hand Strike 3 1 200
6 Orange Left Hand Sweep 1 201
9 Orange Whistle 1 202
10 Orange Left Hand Strike 1 203
7 Orange Talk Back 1 204
8 Orange Left Hand Strike 1 205
13 Orange Roar 1 206
19 Orange All Demo 1 208
20 Orange Power Off 1 209
16 Orange Demo 1 1 210
18 Orange Demo 2 1 211
17 Orange Dance Demo 1 212

/*

Based on IRSend demo from ken Shirriffs library - this sends simple commands to a RoboSapien V1 using
and IR Transmitter with Arduino

*/

#include <IRremote.h>

IRsend irsend;
IRrecv irrecv(11);

void setup()
{
Serial.begin(9600);
}

void loop() {

irsend.sendRSV1(142);
delay(1000);

if (Serial.read() != -1) {

Serial.println("started");
irsend.sendRSV1(129);
irsend.sendRSV1(199);

/*
irsend.sendRSV1(129);
irsend.sendRSV1(129);
delay(1000);
irsend.sendRSV1(169);
delay(2000);
irsend.sendRSV1(162);
delay(2000);
irsend.sendRSV1(173);
delay(2000);
irsend.sendRSV1(196);
delay(2000);
irsend.sendRSV1(206);
delay(2000);
irsend.sendRSV1(199);
delay(2000);
Serial.println("Done");
*/

}

}

Arduino – Pond Filler Upper

I have this little pond see.  Its not terribly big and it looks quite nice – but it has a small leak somewhere.  And its driving me nuts. So in a moment of geekery I thought the problem could be solved with a bit of software and an Arduino board.  So I concocted a small plan to keep the pond topped up.  Nothing too complex – just used a water level sensor and a solenoid driven water valve.  I also used the excellent Ciseco relay for Arduino. Simple and elegant.  Some pics here of the installation.  It’s really just a prototype – if it works I’ll put a more rugged version together.

Parts List

  • Arduino Duemilove
  • Hose Solenoid ( This is one from Ebay ) Its 12v
  • Tank Sensor ( Again from Ebay )
  • Ciseco Relay 
  • Wires of various kinds
  • Project Box
  • Switches
  • LED
  • Resistors – 10k, 1k – switch controls
  • 12-9V Regulator – I used this with a Capacitor so I can drive everything off a 12v DV PSU
  • 12V DC PSU

This is the Sketch to control the board

The sketch is rather simple and a bit clumsy.  I used the timerone library.  It works by trying to detect if the water has been running for more than WATERTIMEOUT.  If it does it waits for WAITIME. If it does that more than SYSTEMJAMED times – then the system switches off.  This should protect it if the sensor jams open.  I reckoned 1 minute at my water pressure was enough to fix the leak.

Still got to check if the sensor bounces for a few seconds but so far it works quite well.

#include <TimerOne.h>

/*
 *  Pond Relay
 *  August 2011 (c) Dave Robertson
 *	Arduino based pond relay with CISECO relay http://www.ciseco.co.uk/content/
 */

#define SYSTEMJAMMED 10      // Number of times the system starts a wait look
#define WATERTIMEOUT 60    // Number of seconds to run the sensor
#define WAITTIME 60    // Number of seconds to wait until running again
// constants won't change. They're used here to
// set pin numbers:
const int sensorPin = 2;     // the water sensor switch
const int switch1Pin = 3;     // control switch 1 - Manual Override
const int switch2Pin = 5;     // control switch 2
const int ledPin =  13;      // the number of the LED pin ( ardunio diag only )
const int relayPin =  7;      // the number of the relay pin that controls the valve

long timerRunning;        // Number of seconds since we started
long waterrunningTimer = 0;
long waitingTimer=0;
const int ledStatus =  4;      // the number of the LED pin

int systemJammed=0;        // The system is jammed so switch it off
int overrideSystem=0;      // Override the system and shut off the valve regardless

int s1State = 0;         // variable for reading the pushbutton status
int s2State = 0;         // variable for reading the pushbutton status
int sensorState = 0;         // variable for reading the pushbutton status
int oldsensorState = 0;         // variable for reading the pushbutton status
int ledFlash =0;
int beginwait=0;    // Controls waiting for next

void setup()
{
  pinMode(10, OUTPUT);
  Timer1.initialize(1000000);         // initialize timer1, and set a 1/2 second period

  Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt

  pinMode(ledPin, OUTPUT);
    pinMode(ledStatus, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(switch1Pin, INPUT);
  pinMode(switch2Pin, INPUT);
  pinMode(sensorPin, INPUT);

  pinMode(relayPin, OUTPUT);

  digitalWrite(relayPin, HIGH);
  delay(2);
    digitalWrite(relayPin, LOW);
  Serial.begin(9600);
  Serial.println("Starting Now 5 Second Delay");

  // Flash to indicate we starting up

  for (int i=0;i<100;i++)  {
        delay(50);
        digitalWrite(ledStatus, digitalRead(ledStatus) ^ 1);
  }
    Serial.println("Entering loop");
}


//
//  Timer call back here - update timers and LED for status
//
void callback()
{

  // Flash the led to show valve is on

    Serial.println(s1State);
    Serial.println(s2State);


  if (systemJammed>SYSTEMJAMMED) {

    Serial.println("System Jammed - all off");

    for(int i=0;i<10;i++) {
      digitalWrite(ledStatus, digitalRead(ledStatus) ^ 1);
      delay(1000);

    }
    return;
  }

//   if (ledFlash)
//      digitalWrite(ledStatus, LOW);
//   else
//      digitalWrite(ledStatus, HIGH);

    if (sensorState && !beginwait) {
       waterrunningTimer+=1;
       Serial.print("Water is running now for secs: ");
       Serial.println(waterrunningTimer);

    }

    timerRunning += 1;
    // We rest after 24 hours as this a fine time window for what we want
    if (timerRunning == 5184000) {
      timerRunning = 0;
      waterrunningTimer = 0;
      Serial.println("Time now");
    }

    // Increment the waiting timer
    if (beginwait) {
      digitalWrite(ledStatus, digitalRead(ledStatus) ^ 1);

      Serial.println("Water ran too long - switched off waiting");
      waitingTimer++;
    }
}

void loop()
{


  // Get the state of water sensor  and switches
  sensorState = digitalRead(sensorPin)^1;
  s1State = digitalRead(switch1Pin)^1;
  s2State = digitalRead(switch2Pin)^1;

  if (s2State == HIGH) {
   // System off - no action
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
    waterrunningTimer=0;
    digitalWrite(ledStatus, LOW);
    oldsensorState = LOW;
    waitingTimer=0;
    beginwait=0;
    systemJammed=0;  // Reset jammed sensor counter

    //Timer1.stop();
    return;
  }
    else {
    //  Timer1.start();

    }

  if (s1State == HIGH) {
    // Override sensors and reset everything
    if ( oldsensorState == LOW)
    {
       waterrunningTimer = 0;
       oldsensorState = HIGH;
    }
    //digitalWrite(ledStatus, LOW);
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
    digitalWrite(ledStatus, HIGH);
    systemJammed=0;
    return;
   }

  if (systemJammed >  SYSTEMJAMMED)
     return;


  if (sensorState == LOW ) {  // Clear everything as water has filled
    // Sensor has read water filled
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
    waterrunningTimer=0;
    digitalWrite(ledStatus, LOW);
    oldsensorState = LOW;
    waitingTimer=0;
    beginwait=0;
    systemJammed=0;  // Reset jammed sensor counter
  }


  if (waterrunningTimer > WATERTIMEOUT ) {
      // Water has been running for over  a minute and the sensor is still high

    sensorState=LOW;    // Switch it off
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
    digitalWrite(ledStatus, LOW);

    oldsensorState = LOW;
    if (!beginwait) {
          Serial.println("Water running too long");
          waitingTimer=0;
          beginwait=1;
          systemJammed++;
      }


  }

  if (beginwait && waitingTimer>WAITTIME){

    Serial.println("Timeout - switching off");
    beginwait=0;
    waitingTimer=0;
    waterrunningTimer=0;

  }


    // The sensor state read

  if (sensorState == HIGH ) {

    if ( oldsensorState == LOW)
    {
       waterrunningTimer = 0;
       oldsensorState = HIGH;

    }
    //digitalWrite(ledStatus, LOW);

    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
    digitalWrite(ledStatus, HIGH);

  }

}

Arduino and LadyAda Wave Shield

I’ve been messing around with my fantastic Arduino board.  The whole Arduino thing is without question an Italian masterpiece of our generation.  I could spend 24 hours a day just messing with it.  The software side is as elegant as the hardware side – the idea you can add C++ and Java libs is stunningly brilliant.

Anyways – I wanted to do something with it – and I decided I wanted to build a simple SFX box for my little rock band.  We use sequencers and MIDI – but I wanted to do AC/DC’s For those about to rock.  The song has some nice cannon fire effects and this really has to be in the mix for a live performance.  So I thought that if the Arduino can be used.  I’ll be doing a more complex project later using Arduino to drive MIDI for live performance.

So I bought a kit for a the Wave Shield from AdaFruit – very very good business that – and sampled some effects.  I then put together a new app based on  the supplied player code on the AdaFruit site – hooked up a couple of footswitches on the Arduino and thats it – super fast special effects in WAV format – for the AC/DC song – some nice real cannon fires.  Hook it all up to the PA and boom.. nice.

This is the Arduino with a Wave Shield all hooked up in test

Footswitch found in dump… RS good quality – works well on stage

Buy the Arduino at RS Components and get the Wave Shield and info at www.adafruit.com/waveshield.  Get the footswitch at your local tip/dump/junkyard/scrapyard