arduino to atiny2313

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tge1986
 
Posts: 28
Joined: Mon Jul 21, 2008 10:09 pm

arduino to atiny2313

Post by tge1986 »

I have some arduino code that i want to put on a atiny2313 as the arduino is overkill, in fact the the atiny2313 is more then i need but i have some to use. it consist of two button that turn a pin high and low to control an mp3 player. here is the arduino code.

Code: Select all

int play_state;

void setup(){
  int onoff_state=0;
  
  pinMode(5,INPUT);  //on off state
  pinMode(6,INPUT); //play
  pinMode(7,OUTPUT); //optoisolator control
}

void loop(){
  int play_state;
  if(digitalRead(5)==HIGH){
    powerOn();
  }
  
  if(digitalRead(6)==HIGH){
    play();
  }
}



void powerOn(){
  digitalWrite(7,HIGH);
  delay(2000);
  digitalWrite(7,LOW);
  play_state=0;
}

void play(){
  if(play_state==0){
    digitalWrite(7,HIGH);
    delay(300);
    digitalWrite(7,LOW);
    play_state=1;
  }
  
  if(play_state==1){
    digitalWrite(7,HIGH);
    delay(300);
    digitalWrite(7,LOW);
    delay(100);
    digitalWrite(7,HIGH);
    delay(800);
    digitalWrite(7,LOW);
    delay(100);
    digitalWrite(7,HIGH);
    delay(300);
    digitalWrite(7,LOW);
  }
}

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Post by mtbf0 »

first of all pinMode, digitalWrite & digitalRead are arduino api functions and won't be available when programming the attiny2313 in c. digital pin 7 on an arduino is pin7 of the atmega168's PORTD. on the attiny2313 PORTD has only 7 pins, numbered 0-6.

your arduino code doesn't do any debouncing of the inputs. you may get away with it since you have lengthy delays in your input processing but sooner or later your player's going to turn on in response to some random electronic noise.

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Post by westfw »

I see about three ways to proceed on this.
  • Port the arduino libraries to ATtiny2313
    Write functions approximately similar to the Adruino ones, for the tiny, from scratch.
    Write a program from scratch that does the same thing overall, without using Arduino-like functions.
I think I'd rate all three as approximately equivalent in difficulty, all rather educational, and probably all a bit beyond someone who had the ask the question in the first place (sorry...)

A better approach may be to figure out how to take the programmed ATmega168 chip out of the arduino after its been programmed, and operate it in "stand alone" mode. Replace the one in the arduino and continue to use the full arduino as the development environment. This, at least, is well documented and explained in various places on the arduino site. An ATmega168 is not THAT much more expensive than an ATtiny2313, even if you get the mega with the arduino already built in. You're looking at a $2.50 chip vs a $5.50 chip; shipping costs may dominate.

User avatar
tge1986
 
Posts: 28
Joined: Mon Jul 21, 2008 10:09 pm

Post by tge1986 »

That was my fall back solution, I've been having some much trouble just getting simple code onto the 2313. I feel using the 168 would be better. I just have to figure out how to get the bootloader onto the chips. the source code is on the arduino site but that's not the problems I've been having, i keep getting held up on the stupid makefiles.

koolkat
 
Posts: 358
Joined: Tue May 06, 2008 8:42 pm

Re:

Post by koolkat »

tge1986 wrote:That was my fall back solution, I've been having some much trouble just getting simple code onto the 2313. I feel using the 168 would be better. I just have to figure out how to get the bootloader onto the chips. the source code is on the arduino site but that's not the problems I've been having, i keep getting held up on the stupid makefiles.
If you have a plain old '168 then you dont "have" to put the bootloader on the chip...

You can make it so that the arduino IDE uses a programmer instead of the bootloader...

here is the link to do that:

http://www.arduino.cc/en/Hacking/Programmer

User avatar
tpwalsh
 
Posts: 3
Joined: Tue Oct 21, 2008 12:37 pm

Re: arduino to atiny2313

Post by tpwalsh »

koolkat wrote:
tge1986 wrote:That was my fall back solution, I've been having some much trouble just getting simple code onto the 2313. I feel using the 168 would be better. I just have to figure out how to get the bootloader onto the chips. the source code is on the arduino site but that's not the problems I've been having, i keep getting held up on the stupid makefiles.
If you have a plain old '168 then you dont "have" to put the bootloader on the chip...

You can make it so that the arduino IDE uses a programmer instead of the bootloader...

here is the link to do that:

http://www.arduino.cc/en/Hacking/Programmer
As a relative n00b to microcontrollers, the arduino's been a great way to get into it, but I'd like to move onto other processors, namely the ATtiny13 or the ATMega32, but I do like the Arduino environment.

So what it sounds like I need to do if I want to stay inside the Arduino IDE, I'd have to write a library specifically for each chip?

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

Return to “Microcontrollers”