help making C-code for the ATtiny2313

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
rocket100
 
Posts: 8
Joined: Thu Jun 04, 2009 8:08 pm

help making C-code for the ATtiny2313

Post by rocket100 »

I am going to build a robot that has flashing lights
And two motors to drive the robot. This is going to be one of my big
ATtiny2313 projects and I am going to make the C source code simple. All
it has to do is make a red led flash four times then a blue led flash
four times with each flash being about 20 milliseconds long with a 50
milliseconds long pause in between. The red light will be PD1 and
ground and the blue light PA1 and ground. Then the 3v motors from
radioshack will be at the back of the bot and they will be connected
kind of like an H-bridge with a positive lead to pin PD2 and a
negative lead to pin PD3 and a positive lead of the motor to the
ground and also the negative lead to ground for the second motor it
goes like this positive to PD4 and negative to PD5 and a positive lead
of the motor to the ground and also the negative lead to ground. And a
bumper switch connected to PB7 and VCC to detect when it bumps the
wall. So here is how the C code works for the motors when it is in a
loop for PD2 and PD4 so both motors to go forward. But when it bumps
something then the loop stops and PD3 and PD5 goes on for 2000
milliseconds(2 seconds) which makes it back up then it turns PD5 right
motor for 3000 milliseconds( 3 seconds) which makes it turn right and
then goes back into the loop so it goes forward again until it hits
something again. And the flashing light are in a separate loop. If
this is way too hard to imagine then here is a datasheet for the
ATtiny2313 ;http://www.datasheet4u.com/html/A/T/T/
ATTINY2313_ATMELCorporation.pdf.html....
So I tried to figure out the code for it but I am not very good at C
because I am just a beginner so if someone could help me write it and
keep it as simple as possible that would be fantastic! I do how ever
know a bit of BASIC code like IF...ELSE or DO....LOOP so that makes
It a bit easier to under stand "C".
Thank you :D :D :D :D :D :D

The_Don125
 
Posts: 373
Joined: Tue Mar 06, 2007 11:51 pm

Re: help making C-code for the ATtiny2313

Post by The_Don125 »

You are going to need circuitry to drive the motors. The tiny2313 cannot drive the motors by itself, you will need at the very least a power transistor.

The 2313 can provide or accept 20mA or 30mA of current on any given pin (except reset, gnd, and vcc), and I don't think (useful) motors exist that can run off of 20mA at 5V.

Also, please format your posts, when it is one huge block of text like that, it is very hard to read, and when asking for free advice, it is advisable to make life as easy as possible for the people helping you.

i.e.
I want to build a robot

it has two lights and two motors. This is how everything is connected

I want it to do this and that

I don't know much code, so I would appreciate advice.

rocket100
 
Posts: 8
Joined: Thu Jun 04, 2009 8:08 pm

Post by rocket100 »

I am going to use relays as a H-bridge.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: help making C-code for the ATtiny2313

Post by Franklin97355 »

You will still need circuitry to drive the relays and don't forget the diodes across the coils to protect your chip.

Start your programming by writing out what you want to happen in small blocks that do only one thing then combine the blocks into a whole. take each block and write what you think the code would be and then check the compiler manual for the correct syntax.

For instance, "I want the red led to blink four times"
high led
pause 20ms
low led
pause 20ms
........(four times)

rocket100
 
Posts: 8
Joined: Thu Jun 04, 2009 8:08 pm

Post by rocket100 »

Ok ,
thanks

User avatar
karlgg
 
Posts: 212
Joined: Sat Dec 27, 2008 2:41 pm

Re:

Post by karlgg »

rocket100 wrote:I am going to use relays as a H-bridge.
Using relays on the outputs might still be problematic, depending on how much current they draw. You'd be better off with power transistors, or better still a motor-control chip (like the ones LadyAda uses in the motor shield). It magically has an H-bridge just waiting for you.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”