Atmel launches the ATtiny104 Xplained Nano evaluation kit, a nice way of introducing this $0.40 microcontroller.
The small and low cost evaluation board includes an on-board programmer.
After received two boards from Digikey, started downloading the Atmel Studio.
The Atmel Studio is a “BIG” tool and takes time for the installation, but after the waiting, everything went smooth.
I spent some time drawing the Pinout Diagram, it helps me to learn more about the mini development kit.
In no time the ATtiny104 was reading the PUSH BUTTON and controlling the on board LED.
Next thing to do: experimenting with the serial port.
The character ‘U’ is sent every 500 milliseconds if the BUTTON is pressed.
The working code transmitting at 9600 bauds:
/* ATTINY104_Serial.c * Created: 3/24/2016 08:20:00 PM * Author : Ardunaut * Program to test serial transmission. * While the BUTTON is pressed: * 'U' character is transmitted every 500 milliseconds. * The LED blinks when a char transmitted. * FOSC=1000000 :"After powering up the device or after a reset the system clock is automatically * set to calibrated internal 8MHz oscillator, divided by 8" (Datasheet pag.32) * Using C functions from: http://www.atmel.com/Images/Atmel-42505-8-bit-AVR-Microcontroller-ATtiny102-ATtiny104_Datasheet.pdf * Note: Zeros ('0') were removed from the register names to make the code compatible. __________ VCC--|1 14|--GND (TPI CLK) PA0--|2 13|--PB3 (CDC TX) -->USART_Transmit() (TPI DATA) PA1--|3 12|--PB2 (CDC RX) <--USART_Receive() (RESET) PA2--|4 11|--PB1 (BUTTON) PA3--|5 10|--PB0 PA4--|6 9|--PA7 (LED) PA5--|7 8|--PA6 \__________/ Atmel ATtiny104 Xplained Nano */ #include <avr/io.h> #include <util/delay.h> #define LED_PIN (1 << PA5) #define BUTTON_PIN (1 << PB1) #define FOSC 1000000 #define BAUD 9600 #define MYUBRR FOSC/16/BAUD //adding or subtracting 1 may be necessary. void PORTS_init(void){ PUEB |= BUTTON_PIN; // Enable Pull-Up function in PB1. PORTB |= BUTTON_PIN; // Set Pull-Up for the Button. DDRA |= LED_PIN; // Configure LED pin as Output. } void USART_Init( unsigned int ubrr) { /*Set baud rate */ UBRRH = (unsigned char)(ubrr>>8); UBRRL = (unsigned char)ubrr; /*Enable receiver and transmitter */ UCSRB = (1<<RXEN)|(1<<TXEN); /* Set frame format: 8data, 2stop bit */ UCSRC = (1<<USBS)|(3<<UCSZ0); _delay_ms(250); PORTA |= LED_PIN; // Switch off the LED. } void USART_Transmit( unsigned char data ) { /* Wait for empty transmit buffer */ while ( !( UCSRA & (1<<UDRE)) ); /* Put data into buffer, sends the data */ UDR = data; } unsigned char USART_Receive( void ) { /* Wait for data to be received */ while ( !(UCSRA & (1<<RXC)) ); /* Get and return received data from buffer */ return UDR; } void USART_Flush( void ) { unsigned char dummy; while ( UCSRA & (1<<RXC) ) dummy = UDR; } /*----------------------------------------------------------------------------------------------------------------------------------------------------------*/ void main( void ){ PORTS_init(); USART_Init(MYUBRR); while(1){ while(PINB & BUTTON_PIN){} // Wait until the Button is pressed. PORTA &= ~LED_PIN; // Switch on the LED. USART_Transmit( 'U' ); // USART_Transmit( 85 ); _delay_ms(50); PORTA |= LED_PIN; // Switch off the LED. _delay_ms(450); } }
Some soldering to continue experimenting with the Xplained NANO in a breadboard.
Now, looking for an efficient code and low power solution to create an IoT node…
First, testing the hardware:
Transmitting at 300 bauds with the USART connected to the 433Mhz RF module:
This is the code to transmit “HELLO” every second (while the button is pressed).
/* * ATTINY104_RF300.c * -Using the USART for 300 bauds transmission with the RF Module (433Mhz). * -Tree 0xAA bytes are sent as preamble of the message to balance the receptor. * -While the BUTTON is pressed "HELLO" message is transmitted every second aprox. * -Characters are separated 50 milliseconds (20 milliseconds of mark). * -The LED is ON during the message is transmission. * -FOSC= 1000000 : "After powering up the device or after a reset the system clock is automatically * set to calibrated internal 8MHz oscillator, divided by 8" (Datasheet pag.32) * -Using C functions from: http://www.atmel.com/Images/Atmel-42505-8-bit-AVR-Microcontroller-ATtiny102-ATtiny104_Datasheet.pdf * -Note: Zeros ('0') were removed from the register names to make the code compatible. * -Created: 3/26/2016 07:25:00 PM * -Author : Ardunaut __________ VCC--|1 14|--GND (TPI CLK) PA0--|2 13|--PB3 (CDC TX) -->USART_Transmit() (TPI DATA) PA1--|3 12|--PB2 (CDC RX) <--USART_Receive() (RESET) PA2--|4 11|--PB1 (BUTTON) PA3--|5 10|--PB0 PA4--|6 9|--PA7 (LED) PA5--|7 8|--PA6 \__________/ Atmel ATtiny104 Xplained Nano */ #include <avr/io.h> #include <util/delay.h> #define LED_PIN (1 << PA5) #define BUTTON_PIN (1 << PB1) #define FOSC 1000000 // Clock Speed #define BAUD 300 #define MYUBRR FOSC/16/BAUD-1 void PORTS_init(void){ PUEB |= BUTTON_PIN; // Enable Pull-Up function in PB1. PORTB |= BUTTON_PIN; // Set Pull-Up for the Button. DDRA |= LED_PIN; // Configure LED pin as Output. } void USART_Init( unsigned int ubrr){ //Set baud rate: UBRRH = (unsigned char)(ubrr>>8); UBRRL = (unsigned char)ubrr; //Enable receiver and transmitter: UCSRB = (1<<RXEN)|(1<<TXEN); // Set frame format: 8data, 2stop bit : UCSRC = (1<<USBS)|(3<<UCSZ0); _delay_ms(250); PORTA |= LED_PIN; // Switch off the LED. } void USART_Transmit( unsigned char data ){ // Wait for empty transmit buffer: while ( !( UCSRA & (1<<UDRE)) ); // Put data into buffer, sends the data: UDR = data; } unsigned char USART_Receive( void ){ // Wait for data to be received: while ( !(UCSRA & (1<<RXC)) ); // Get and return received data from buffer : return UDR; } void USART_Flush( void ){ unsigned char dummy; while ( UCSRA & (1<<RXC) ) dummy = UDR; } /*----------------------------------------------------------------------------------------------------------------------------------------------------------*/ void main( void ){ PORTS_init(); USART_Init(MYUBRR); while(1){ while(PINB & BUTTON_PIN){} // Wait until the Button is pressed. PORTA &= ~LED_PIN; // Switch on the LED. USART_Transmit( 0xAA ); // To balance the receptor. _delay_ms(50); USART_Transmit( 0xAA ); // To balance the receptor. _delay_ms(50); USART_Transmit( 0xAA ); // To balance the receptor. _delay_ms(50); USART_Transmit( 'H' ); _delay_ms(50); USART_Transmit( 'E' ); _delay_ms(50); USART_Transmit( 'L' ); _delay_ms(50); USART_Transmit( 'L' ); _delay_ms(50); USART_Transmit( 'O' ); PORTA |= LED_PIN; // Switch off the LED. _delay_ms(650); // delay to complete one second. } }
More experiments and learning …
testing….3GB Windows Software on hdd for programming 1KB atmel ? hi hi .. unusable…
Hi, and thank you for sharing with us. So I tried the second example with multiple characters being transmitted 50ms apart and the data appears to get corrupted when the baud rate is increased from 300 (in your example) to 9600. Do you have any ideas why?
Thanks.
The transmission rate limit is 10Khz but with a very distorted wave shape (rise and fall times are different). Asincronous serial may be not the best approach if you want to maximize the baudrate.
Roman Black did some work on TX routines for these cheapo modules; and managed to get reliable speeds and range; he was using PIC micro’s,but it should yield some useful ideas for other chip families too.
Roman Black did some work on these cheapo FR links with PIC micro’s; he managed (with some clever tricks) to get range, speed, and reliability! and all from the cheapest, crudest RF modules on the planet!
P.S had trouble logging in with wordpress,as my login details dated back to 2008…!
Did you also experiment with the receiving part? I can’t get that one to work so far…