I decided it was time for me to play around with wireless communication as I recently purchased a wireless alarm system. I was able to pick up two nRF24L01 wireless modules very cheaply at about $2 each from Ebay.
Some features of this chip are:
126 channels
Up to 32 bytes payload data
Up to 2Mbps
About 12mA current consumption when receiving or transmitting
The nRF24L01 modules uses 6 data pins but you can get by with only using 5. There are 4 for the SPI, 1 for the chip enable (CE) which sets the nRF24L01 in listen or transmit mode and an interrupt pin (IRQ) which can alert us when a packet arrives, packet is sent or maximum retries reached. I don’t use the interrupt pin in my example.
In my example, I have the transmitting code running on the ATtiny and the receiving code running on the Arduino so I could easily print the results. We run the nRF24L01 from the 3.3V pin on the Arduino.
For some time I’ve been meaning to do a new video which covers why using 100% of SRAM can sometimes introduce bugs. I discovered this when I was working on the Nokia 3120 Keypad SMS Sender, the SMS message that I was sending would be cut short and would have weird characters at the end. I loaded up the hex file in AVR Studio 4 and found that the stack was overwriting my variables!
I recently received a question in regards to the thermistor formula found on one of the SATL build posts asking how I came about the variables used in the thermistor formula. The thermistor formula and variables I used can be found on the Arduino Playground however it made me think if the formula being used was accurate for the Vishay 10K thermistor I was using.
Below we have the Thermistor function in question in which it converts the ADC value to a resistance value in ohms, applies a formula and convert the result to celsius.
double Thermistor(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000)); // Minus by 10K as that's the resistor in series with the thermistor
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
Steinhart–Hart equation
The formula used is called the Steinhart–Hart equation which models resistance to temperature, there is the “full version” and the “commonly used” one. A, B, C and D in the functions below are called the coefficients.
Full version: 1/T= A + B*ln(R/Rt) + C*ln(R/Rt)2 + D*ln(R/Rt)3
Commonly used: 1/T= A + B*ln(R/Rt) + D*ln(R/Rt)3
In this video I show how you can use a 32KHz watch crystal on an ATtiny85 for precise timing.
We use the timers overflow to indicate when 1 second has passed which wakes up the ATtiny85 and turns an LED on or off and then goes back to sleep (which when in sleep mode with the LED off, it consumes about 60-70uA of current).
This can be used for applications such as clocks, data loggers, etc. If you are looking to minimise the current consumption when sleeping you’ll need to find a AVR with an independent timer clock like the ATmega328 so you can put the AVR on power-down whilst the timer is still running.
Today we’ll introduce the N Channel Mosfet and show how we can use it to allow us to switch between voltage sources.
Mosfet explained and example
We can think of a mosfet sort of like a transistor, it has a gate, drain and source compared to the transistor which has base, common and emitter.
With transistors that we want to act as a simple switch it’s all about adjusting the current at the base however with mosfets it’s actually the voltage at the gate that turns them on. Because we don’t lose current when turning the mosfet on, this means that it’s actually more efficient than a transistor.
In datasheets you see it called Vgs and they provide you a minimum voltage that is needed before the mosfet will allow current to flow through the drain and the source.
In this demo we show how we can change the ATtiny85 clock speed on the fly by modifying the prescaler. We note that using _delay_ms() is subject to the F_CPU and if we double the MHz we need to double _delay_ms() in order for the timing to be correct. Changing the clock speed on the fly may be useful for power saving applications where there might be brief moments to increase the clock speed, e.g. communicating with devices like USB.
Today I’ll be showing you one of the example projects of V-USB called EasyLogger, it’s basically a project using the ATtiny45 that logs a voltage and writes the value to your computer via USB. I choose EasyLogger because it’s very similar to the sort of things I’ll be using, i.e an ATtiny85 and no external crystal.
It looks pretty simple but to make it even simpler we’ll actually be ignoring the LED, button and input voltage so it’s just the USB connection and nothing else.
So the Arduino software has been easy to use but I’m thinking about using V-USB in one of my projects. V-USB is an implementation of the USB protocol that can run on an Atmel AVR microcontroller but in order to integrate it into one of my projects it’s time to move away from the Arduino software.
I’ll show you how we can create our own version of the ATtiny45/85 Blink without the Arduino software. We will use setup/timer functions from the internal Arduino wiring.c file because it’s easier to use something that works.
First thing we’ll do is download WinAVR from http://winavr.sourceforge.net. After installation, the default directory is C:\WinAVR-20100110.
But before we start with WinAVR we need a starting template, so what I did was download AVR Studio 5 Beta and start a new blank project. The reason I’m using Programmers Notepad instead of AVR Studio is that it’s a very simple interface and from my testing actually compresses things better when compiling.
So I’ve been able to read/write to a Gameboy cartridge so the next step is emulating one using an Arduino. I wasn’t be able to emulate the whole cartridge using my current methods but I did emulate the cartridge sending the Gameboy the Nintendo Logo. I’ll show you how we can analyse the data coming from the Gameboy and the various steps I went through to get it working.
Let’s jump to the Youtube video straight away to see the results.
The first thing required is a Gameboy that we can solder some wires to; the Gameboy that I took the cartridge header from was perfect for this and then just place those wires into a breadboard.
Learn how to use the Pin Change Interrupt on the ATtiny85 to wake up the microcontroller from sleep. Using the Pin Change Interrupt you can use any of the ATtiny’s 6 pins however remember that all 6 will trigger the same interrupt vector PCINT0.
AdvanceVGA – Play your GBA on the big screen! Swap out the LCD for our board, solder some wires, connect 5V USB and VGA and you’re ready to go.
GBxCart RW allows you to backup GB/GBC/GBA ROMs, save or restore game saves and re-write supported flash carts. Mini RW option available for GB/GBC only.
Wireless Gameboy Controller – Use your Gameboy, mGB, GBC, GBA, GBA SP, GB Micro, NDS and NDS Lite as a wireless controller on Windows, Linux, Raspberry Pi, etc, and on your NES, SNES, N64, Gamecube and Wii.