/* * target cpu: atmega168 * registers like UCSR0A are named differently on a atmega32 for example, watch out! * * this code receives data over the uart from a HC-05 bluetooth module * and switches on led1 if the character that was received is: h * and led2 if the character is z * * * ---- * tested with: * bluetooth terminal * qwerty.bluetooth terminal * * i know the name looks stupid, but thats how the coder decided to go * https://play.google.com/store/apps/details?id=Qwerty.BluetoothTerminal&hl=en * * version: 6.1104 * e-mail: aries156@gmail.com * * in the setup, activate '\r\n' line endings * note: tested other bluetooth apps, but this free one just worked * * to use the software: * ONLY THE FIRST TIME: you need to "pair" the devices - for whatever reason, bluetooth likes to get to know each other * when you first make contact (like that worked out with the bork) - so you "pair" your device with a PIN code. * the hc05 modules pin code is the extremely secure "1234" just to make pairing absolutely useless. (from a security point of view) * * * start the app, choose: connect a device - insecure * select your hc-05 module (default name: HC-05) * type a h to activate led1 * type a z to activate led2 * ---- * * circuit: * hc05 rx -> atmega168 tx (PD1) * hx05 tx -> atmega168 rx (PD0) * * voltages: * 5V supply voltage: * i was running the circuit at 5V, so i needed a voltage devider between the atmega TX and the HC05 RX * to get the voltage down from 5v to about 3.3v * * the modules operating voltage is 3.3v - 6v, so yes you can attach 5v to VCC of the module * but the voltage for the RX on the HC05 is 3.3V - so do a voltage divider * 3.3v supply voltage: * NOT TESTED, but should work just fine. skip the voltage divider. * * ---- * * * * code by: julius junghans */ // atmega 168 #include #include #include #include // you always read online that the modules are preset to 9600 bauds, i just found one source who said otherwies. // but that source could have been confused by the fact that the AT command mode works with 38400 #define BAUD 9600 /* * dont forget to define F_CPU in the Makefile. * something like: * F_OSC = 16000000 * F_CPU = $(F_OSC) * CFLAGS = -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) * * sometimes F_OSC is used, probably just another name for F_CPU */ #define MYUBRR ((uint16_t) ((F_CPU / ((BAUD) * 16.0)) + .5) - 1) #define LED1 PB0 #define LED2 PC5 // contains what the bluetooth module received uint8_t data; void USART_Init(unsigned int ubrr) { // set baud rate UBRR0H = (unsigned char)(ubrr>>8); UBRR0L = (unsigned char)(ubrr); // enable receiver, transmitter and interrupts for rx/tx UCSR0B = (1<