Showing posts with label Pro Mini. Show all posts
Showing posts with label Pro Mini. Show all posts

Sunday, February 23, 2014

Arduino Compatible robot for £15

I was looking for a low cost way of building a vehicle controlled by an Arduino or Raspberry Pi and eBay once again came up with the solutions.

1 x Smart Robot Car Chassis Kit  - £7.60
1 x L298N - £1.86
1 x Arduino Compatible Pro Mini - £2.53

Total Cost: £11.99

The Smart Robot Chassis comes with 2 motors and wheels.  It comes with the encoding wheels for optical encoder to measure rotation, but without the electronics.
All the parts with chassis. 


The L298N is a Motor Driver Module
That's it on the right next to the battery pack


While the Pro Mini is a small Arduino compatible board that I previously blogged about programming (http://winkleink.blogspot.co.uk/2014/01/programming-arduino-pro-mini-16mhz-5v.html) and soldering the headers (http://winkleink.blogspot.co.uk/2014/01/soldering-up-pro-mini-arduino.html)

You need a USB to serial adaptor to program it. For this adaptor you have to solder a pin to the DTR and then attach that to the RST line on the Pro Mini when programming.

I built the Chassis and attached the L298N
All the parts

Bits for the front wheel mounting
Screw the spacers to the chassis


Attach the swivel wheel to the spacers.
Note nuts not in original picture

Parts for motor/wheel mount

Use small screws to attach pillars to chassis

Parts for connecting motors

Screw motor to the outside of the pillars.
Note: make sure to have motor connectors on the inside
for easy cable management

Add the encoder wheels if you want and the actual wheels

See in front of batter holder are the two holes where
the battery holder will be bolted to.
Use 2 of the slightly longer bolts for this.

All finished.  Still needed to solder the wires to the motors.


The L298N is then wired.

+ Battery to VCC and 5V on the L298Nand RAW on the Pro Mini. The L298N appears to be OK with 6V going to the 5V line. And the Pro Mini doesn't complain about the 6V from the batteries either.
As always connect all the GNDs together

Then for each motor connect Out1 and Out2 to one Motor and Out3 and Out4 to the other motor. Depending on which way around you do the connection will decide which way the motors spins, so if this is wrong you can either swap the wires or modify the code.

Then for control from the Pro Mini I connected

IN1 to 3
IN2 to 5
IN3 to 9
IN4 to 10

The eagle eyed will have noticed these are 4 of the PWM lines so in the future I can enable speed control by driving using PWM rather than digital.


Uploaded the following Sketch tot he Pro Mini and let it rip - see video at the bottom

// motor driver using PWM

int lb = 3;
int lf = 5;
int rb = 10;
int rf = 9;


void setup() {
  // put your setup code here, to run once:

  pinMode(lb, OUTPUT); 
  pinMode(lf, OUTPUT); 
  pinMode(rb, OUTPUT); 
  pinMode(rf, OUTPUT); 
  
  digitalWrite (lb, LOW);
  digitalWrite (lf, LOW);
  digitalWrite (rb, LOW);
  digitalWrite (rf, LOW);

}

void loop() {
  // put your main code here, to run repeatedly: 
  
    digitalWrite (lf, HIGH);
    digitalWrite (lb, LOW);
    digitalWrite (rf, HIGH);
    digitalWrite (rb, LOW);

    delay(1000);

    digitalWrite (lf, LOW);
    digitalWrite (lb, LOW);
    digitalWrite (rf, LOW);
    digitalWrite (rb, LOW);

    delay(1000);

    digitalWrite (lf, LOW);
    digitalWrite (lb, HIGH);
    digitalWrite (rf, HIGH);
    digitalWrite (rb, LOW);

    delay(600);

    digitalWrite (lf, HIGH);
    digitalWrite (lb, LOW);
    digitalWrite (rf, HIGH);
    digitalWrite (rb, LOW);

    delay(1000);

    digitalWrite (lf, HIGH);
    digitalWrite (lb, LOW);
    digitalWrite (rf, LOW);
    digitalWrite (rb, HIGH);

    delay(600);
}



All worked well.
Next I need to put in place a way of controlling it remotely.
The adventure continues.

Note: This chassis and L298N should also work with a Raspberry Pi. Need to be more careful with the power and a few other bits. 


Tuesday, January 21, 2014

Reading IR Remote using TSOP1838 and Arduino Compatible Pro Mini

After getting the Arduino compatible Pro Mini all soldered up and programmed using the CP2102 serial adaptor I thought it would be see if it works with the TSOP1838 Infra Red Receiver.  I bought 2 from eBay as I want to rig up a couple of Arduinos to send and receive 'messages' from each other.

I started by testing with my Arduino Uno with Ethernet Shield attached. It was the nearest to hand so I thought I might as well see if the TSOP1838 works with it.
TSOP1838 on small board with pins for use with breadboard

After finding a blog post that explains the Pins are transposed.  From top to bottom in the picture above it is
OUT - connected ot digital pin on the Arduino
VCC - VCC
GND - GND

Compared to the actual pin outs for the PSOP1838 OUT and VCC are swapped.

Then as I expected I'm late to the party I checked if there was a handy library already in place to take if the decoding and I found the fantastic Ken Shirriff Library

Wired it all up correctly and used the library provided.
Uploaded the IRrecvDemo sketch provided with the library and when I pressed a button a remote control the LED on the IR board flashed so date was being received but nothing was appearing on the Serial Monitor.
I tried switching pins.
I added an extra Serial.prinln to output directly the logic on Pin 11 (default in the Example)
I looked at the code and noted it uses Interrupts

Then  I remembered the Ethernet Shield uses Interrupts. Maybe the Ethernet Shield is was stopping the IR Receiver from working.  So, off came the Ethernet Shield. Rewired the circuit. All 3 wires...and it worked perfectly and reliably.

Then it was onto seeing it it would work with the Pro Mini from eBay.

Wired OUTto Pin4. Note VCC middle and GND on the right above.
Wired it all up as per the programming blog post. Added the IR Receiver and uploaded the same sketch after remembering to change the board from Arduino Uno to Arduino Duemilanove w/ ATmega328.
This time it worked first time. No reconfiguring. No modification of the code.

It means for £1.18 (TSOP1838) and £2.15 (Pro Mini) a total of £3.33 I can read remote Infra Red Remote controls and with the simple addition of an IR LED and a resistor I can also send IR codes. I have IR LEDs somewhere in my box of wires, so a little hunt will be needed to find them. It will be fun to see if I can send codes to my TV.

NOTE: The Ken Shirriff Library includes codes to emulate various remote controls, so the library can handle send and receive.