ATtiny / Arduino IDE Installing the Core

Step 1.  Download the ATtiny Arduino core

  1. Download the latest version

I’m using the latest version for Arduino 1.0 and have only had one problems with (float), but,  I got lucky and found a path for the (float) issue <here>  I’m using windows OS so I downloaded WINDOWS ld.zip file just follow the installation instruction.

Step 2. Also Download the ATtiny PinChangeInterrupt

This make live a lot easier if you want to set a ATtiny pin interrupt, I want to thank the person who wrote this library, before I found this I spent hour trying to figure out how to set interrupt on ATtiny pin.

Using attachPCIterrupt:

#define pin 0 // Set interrupt on digital pin 0

/*defines when the interrupt should be triggered. 
  LOW to trigger the interrupt whenever the pin is low.
  CHANGE to trigger the interrupt whenever the pin changes value.
  RISING to trigger when the pin goes from low to high.
  FALLING for when the pin goes from high to low.
  HIGH to trigger the interrupt whenever the pin is high.

noInterrupts(); // I use to disable global interrupts 
interrupts();   // I use to Re-enable Interrupts        
*/

void setup(){

attachPcInterrupt(pin, Subroutine, FALLING);
//or
detachPcInterrupt(pin, Subroutine, FALLING);
}

void loop(){

}

void Subroutine(){
Do something...
}

Step 3. Download ATtint TinyTuner

I have not had any luck with this library, still cannot make it work.

Step 4. Other very use-full Libraries

  1. TinyDebugSerial or Here (It’s part of the core now)
    This option is TX only, that is you can send serial information from the tiny to your computer, and not the other way, but for debug information this is also usually what you want.
    Serial output pine:
    Attiny84 -PIN PB0
    Attiny85 – PIN PB3
    Attiny2313 – PIN PD1
    but
    You can change the TX pin by modifying TinyDebugSerial.h.
    The section of interest starts at line #610.Change TINY_DEBUG_SERIAL_BIT from 2 to 0.

    /* Works Just like Serial I/O on Arduino except TX only*/
    
    #include <TinyDebugSerial> 
    
    void setup() {
    Serial.begin(9600);
    }
    
    void loop() {
    Serial.println("Testing..");
    }

    Note: Mar 04, 2014: Discovered Serial.write(0) error (call of overloaded write(int)’ is ambiguous) Solution Found Here

    • Any time you have a hardware serial write command with zero as argument such as Serial.write(0) or Serial.write(‘\ 0′), you will have to replace them with the following: Serial.write((uint8_t)0). The reason behind this is that in the new Print class, which Serial class inherits from, the write(char*) method is no longer virtual but actually defined. This write(char*) method and the write(uint8_t) method are both non-virtual and become ambiguous when the argument is zero. The zero could mean zero BYTE value or zero pointer to char array, which is allowed (no other constant values are allowed as pointer). To clear it up, you force the zero into BYTE, or the unsigned 8-bit integer type: uint8_t.
    • Any other libraries that derive from the Print class will have the same issues. You have to do the above regarding to write(0).

    .

    Simple ATtiny RS232 RX Level Converter Schematic:
    arduino-attiny-simple-rs232-RX-level-converter

  2. SoftwareSerial or Here
    If you use this option you have a two way communication, just as you are used to from the Arduino environment. You can set TX/RX to any pin. If you only need tx or rx you can set the unused option to -1, like this

    const int rx=3;
    const int tx=-1;

    The disadvantage of using SoftawareSerial is that you might have to tune the internal oscillator to get a stable connection. Another thing is that it use more memory than TinyDebugSerial. If you need to tune the internal oscillator you can use TinyTuner:

    #include 
    const int rx=3;
    const int tx=1;
    
    SoftwareSerial mySerial(rx,tx);
    int i=0;
    char buf[12];
    
    void setup()
    {
    pinMode(rx,INPUT);
    pinMode(tx,OUTPUT);
    mySerial.begin(9600);
    }
    
    void loop()
    {
    if (mySerial.available()>0){
    buf[i]= mySerial.read();
    if (int(buf[i])==13 || int(buf[i])==10 ){ //If Carriage return has been reached
    mySerial.println(buf);
    for(int x=0;x<=10;x++){
    buf[x]=' ';
    }
    i=0; //start over again
    
    } //if enter
    i++;
    } //If mySerial.available
    }//LOOP
  3. VirtualWire .pdf

    VirtualWire(v1.6) is an library for Arduino, ATtiny, Maple and others that provides features to send short messages, without addressing, retransmit or acknowledgment, a bit like UDP over wireless, using ASK (amplitude shift keying). Supports a number of inexpensive radio transmitters and receivers. All that is required is transmit data, receive data and (for transmitters, optionally) a PTT transmitter enable. Can also be used over various analog connections (not just a data radio), such as the audio channel of an A/V senderTX Example

    // transmitter.ino
    //
    // Simple example of how to use VirtualWire to transmit messages
    // Implements a simplex (one-way) transmitter with an TX-C1 module
    //
    // See VirtualWire.h for detailed API docs
    // Author: Mike McCauley (mikem@airspayce.com)
    // Copyright (C) 2008 Mike McCauley
    // $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
    #include 
    void setup()
    {
    Serial.begin(9600); // Debugging only
    Serial.println("setup");
    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000); // Bits per sec
    }
    void loop()
    {
    const char *msg = "hello";
    digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);
    delay(200);
    }

    RX Example

    // receiver.ino
    //
    // Simple example of how to use VirtualWire to receive messages
    // Implements a simplex (one-way) receiver with an Rx-B1 module
    //
    // See VirtualWire.h for detailed API docs
    // Author: Mike McCauley (mikem@airspayce.com)
    // Copyright (C) 2008 Mike McCauley
    // $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
    #include 
    void setup()
    {
    Serial.begin(9600); // Debugging only
    Serial.println("setup");
    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000); // Bits per sec
    vw_rx_start(); // Start the receiver PLL running
    }
    void loop()
    {
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
    int i;
    digitalWrite(13, true); // Flash a light to show received good message
    // Message with a good checksum received, dump it.
    Serial.print("Got: ");
    for (i = 0; i < buflen; i++)
    {
    Serial.print(buf[i], HEX);
    Serial.print(" ");
    }
    Serial.println("");
    digitalWrite(13, false);
    }
    }

    Simple Arduino/ATtiny RS232 TX/RX Level Converter Schematic:

    arduino-attiny-simple-rs232-TX-RX-level-converter

Advertisements