Search code examples
carduinoraspberry-pihexavr

Uploading the .hex file from ArduinoIDe with a raspberry pi to an attiny85


I, i'm programming an attiny85. First i did it with my raspberry pi and it was ok to make a programm that turn on/turn off the led connected to my attiny85. But there is just a fex tutorial on the net to programm attiny with raspberry pi but there is many one with Arduino . So i decided to use the arduino ide, then get the .hex file and upload it on the attiny with my raspberry pi. ( i don't have arduino board ). More over the arduino ide has many library that make your life simple. But when i upload it everything is ok but the programm seems not working. I don't really know if that's possible to create the .hex file with arduino and push with Raspberry pi. Ps: Sorry english is not my native language Here the first programm i made with raspberry and who works :

#define F_CPU 1000000L
#include <avr/io.h>
#include <util/delay.h>
int main(void)
 {

    PORTB = 0xFF;   // LED's are off

  for (;;) {

     DDRB = 1<<DDB4 | 1<<DDB1 | 1<<DDB0 | 1<<DDB3;
    //PORTB ^= 0xFF;   // invert all the pins
     _delay_ms(1000); // wait some time
     DDRB = 0<<DDB4 | 0<<DDB1 | 0<<DDB0 | 0<<DDB3;
     _delay_ms(1000); // wait some time

   }
   return 0;
}

And then the programm i made with arduino ( i know it's only should turn on 2 led but none are on ) :

void setup() {

 pinMode(1, OUTPUT);
 pinMode(2, OUTPUT);

}


void loop() {
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  delay(1000);              // wait for a second
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);  // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

And to push it i use this command ( for both programm, but for the first one i compile it first to generate the.hex ):

sudo gpio -g mode 22 out
sudo gpio -g write 22 0
sudo /usr/local/bin/avrdude -p t85 -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:blinky.hex

So is it normal ? Is this a code problem or i can't do what i try ? I really want use arduino IDE because i want my attiny/rasbperry communicate by serial gpio


Solution

  • Ok it's work ! :D In fact to compile/push the blinky.c i was using a makefile ( i found it on a tuto ). So now i just take the .hex and use " make install ", as i did with the first blinky but without the compilation as i get the .hex and not the .c So here the makefile :)

    MCU=attiny85
    AVRDUDEMCU=t85
    CC=/usr/bin/avr-gcc
    CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=$(MCU)
    OBJ2HEX=/usr/bin/avr-objcopy
    AVRDUDE=/usr/local/bin/avrdude
    TARGET=arduiblinky
    # target = name of your file you want upload on the attiny
    
    all : 
    # no need this part if you have the .hex :D
        #$(CC) $(CFLAGS) $(TARGET).c -o $(TARGET)
        #$(OBJ2HEX) -R .eeprom -O ihex $(TARGET) $(TARGET).hex
        #rm -f $(TARGET)
    
    install : all
        sudo gpio -g mode 22 out
        sudo gpio -g write 22 0
        sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 9600 - U flash:w:$(TARGET).hex
        sudo gpio -g write 22 1
    
    noreset : all
        sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:$(TARGET).hex
    
    fuse :
        sudo gpio -g mode 22 out
        sudo gpio -g write 22 0
        sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 
        sudo gpio -g write 22 1
    
    clean :
        rm -f *.hex *.obj *.o
    

    But does someone can explain me why it's work when i use the make file and why it's does not work when i do that :

    sudo gpio -g mode 22 out
    sudo gpio -g write 22 0
    sudo /usr/local/bin/avrdude -p t85 -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:blinky.hex
    

    Thanks and i hope it could help someone :)