Today I’ll be showing how we can integrate the Standalone Temperature Logger (SATL) into the V-USB Test program we have. It’s taken me a little while to find my way around V-USB and its kinks.
Schematic
The schematic has been updated to include the USB port. Another change is that when the LED turns on it also turns on the thermistor, before we used to do this with the dataPin.
Cleaning up the V-USB code
The first thing I’ve done is copy over our setup.c file from the SATL WinAVR to our project and then move everything related to V-USB setup or procedures (except the sending of keys) to our setup.c file which now leaves us with just two functions in main.c (evaluateADC and main).
Next I would like to cut down on the main’s USB setup code, lets make a new function called startUSB() and place all the code below in it.
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 we’ll be modifying the ATtiny85_Blink WinAVR example to convert the Standalone Temperature Logger from using the Arduino software to WinAVR so that we can easily integrate it in with V-USB. Download here: Standalone_Temperature_Logger_v2.0_Beta_1
Changes to setup.c
Let’s begin with the setup.c file, to make things easier we will put all of our commonly used functions in this file too.
First we put in the Thermistor function without any changes made.
// Used from http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/
void system_sleep(void) {
DDRB &= ~((1<<ledPin) | (1<<dataPin)); // Set outputs to inputs to save some power
cbi(ADCSRA,ADEN); // Switch Analog to Digital converter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode
sleep_mode(); // System sleeps here
sbi(ADCSRA,ADEN); // Switch Analog to Digital converter ON
DDRB |= ((1<<ledPin) | (1<<dataPin)); // Set those outputs back to outputs
}
Next we insert the system_sleep function, other than the switching between outputs and inputs which is done using DDRB. Notice that we have referenced ledPin and dataPin, we will define those ports in the main.c file.
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 I’ve finally gotten myself a USBtinyISP Programmer to use instead of the Arduino acting as an ISP. It comes with a 10 and 6 pin cable. For my needs I’ll just be using it on a breadboard and using wires from the 6 pin cable was a little tedious.
I decided just to make a simple PCB to convert those 6 pins (2×3 pins) into a 6 pin header specifically made for the ATtiny25/45/85 as it you can just simply plug it on the right hand side of the ATtiny and then just wire up the Reset and Ground lines.
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.