Sometimes it is cheaper to buy a ready-made device than to collect it yourself. Yes, and a home-made device is not always and not everyone will look neat, it depends on the availability of equipment / materials and direct hands.
Users familiar with Atmel microcontrollers or at least Arduino are most likely aware of the cheap USBasp programmer, which costs about $ 3 on Ebay. Two versions of the programmer are distributed:
USBasp 2.0 - with 3.3 volt stabilizer.
USBasp 3.0 is a smaller board with no stabilizer. Also, the ports PD0 and PD1 (Hardware UART) are not connected to the connector. I did not hold it in my hands and will not consider it accordingly.
Below we will look at how to turn the USBasp programmer into an I2C-USB adapter, learn how to read humidity and temperature sensors, get a simple set of input / output ports (PIO), RS232-USB, and also try to create an nRF24L01-USB device for reading wireless sensors and controls devices. Well, for fans of Arduino - we will program in the Arduino IDE using USBasp as a breadboard. Projects use the popular
V-USB library for working with USB in a software implementation.
Archive with firmware can be downloaded at the end of the article. I intentionally do not publish here direct links to my projects - you will find them in the archive.
')
Device Programmer USBasp
The programmer consists of a small number of parts. The brain of the programmer is the Atmega8 microcontroller, which has only 8 kb of flash memory and 1 kb of RAM (SRAM). It seems like a weak microcontroller by modern standards, but so much can be done on it. 12 MHz Accordingly, when writing your firmware, you need to take this into account.
USBasp has a 10-pin connector to which 6 pins of the microcontroller are connected: PB5 (SCK), PB4 (MISO), PB3 (MOSI, PWM), PB2 (PWM), PD0 (RXD), PD1 (TXD). Power supply 5V or 3.3V which is switched by jumper JP1.
The board has two built-in LEDs on the PC0 and PC1 pins. The PB0, PB1, and PD2 m / c pins are used for USB software, PC2 is connected to jumper JP3. The other pins of the microcontroller are not soldered.
You can find the device map in the archive at the end of the article.
Install the bootloader on the board
For a quick firmware change, without third-party programmers, you can install the USBaspLoader bootloader. The official page of the
USBaspLoader project
Unfortunately, the bootloader takes 2 kb of flash memory, but for most applications we have enough of the remaining 6 kb.
Bootloader installation:
Programming team using Arduino as a programmer:
avrdude -c avrisp -P COM1 -b 19200 -p m8 -U flash:w:boot_m8.hex -U hfuse:w:0xc0:m -U lfuse:w:0x9f:m -U lock:w:0x2f:m
Programming command via another USBasp:
avrdude -c usbasp -p m8 -U flash:w:boot_m8.hex -U hfuse:w:0xc0:m -U lfuse:w:0x9f:m -U lock:w:0x2f:m
After that, you can already upload your firmware without a programmer with a standard command
avrdude -c usbasp -p m8 -U flash:w:_.hex
In order to “pour” the firmware into a device with a USBaspLoader installed, you need to set jumper JP3, which puts the device into programming mode and reset the device, closing the contact close to the jumper of power selection (JP1) on jumper JP2 to ground.
Using USBasp as a development board in the Arduino IDE
For firmware in the Arduino IDE (tested on versions 1.0.x) it is necessary to enter the following text in the board.txt file:
atmega8usb.name=ATmega8 USB 12 MHz atmega8usb.upload.protocol=arduino atmega8usb.upload.maximum_size=6144 atmega8usb.upload.speed=19200 atmega8usb.bootloader.low_fuses=0x9f atmega8usb.bootloader.high_fuses=0xc0 atmega8usb.bootloader.path=atmega8 atmega8usb.bootloader.file=boot_m8.hex atmega8usb.bootloader.unlock_bits=0x3F atmega8usb.bootloader.lock_bits=0x2F atmega8usb.build.mcu=atmega8 atmega8usb.build.f_cpu=12000000L atmega8usb.build.core=arduino atmega8usb.build.variant=standard
After that, in the Arduino IDE you can select the appeared ATmega8 USB 12 MHz board. Firmware is carried out through the menu "download using the programmer."
Arduino numbering pins available: 13 (SCK), 12 (MISO), 11 (MOSI, PWM), 10 PB2 (PWM), 1 (TXD), 0 (RXD). Also digital outputs 14 and 15 are available for controlling LEDs on the board.
You can use the USB interface using the library for the Arduino V-USB, but there are fewer features than in C.
nRF24L01-USB
Allows you to exchange data between the nRF24L01 / nRF24LE1 and a computer with the device nRF24L01-USB. Theoretically, up to 22 clients are supported (with a 32-byte transmission packet) based on nRF24L01 / nRF24LE1, but so far it has been tested in practice up to 3. The limitation is due to the fact that the device receives and sends data to the device’s RAM, and 1kb. The size of the receiving packet can be up to 32 bytes, and sending - 4 bytes, this limitation is associated with the way the implementation of work with the library V-USB.
The operation of the nRF24L01-USB adapter is based on time division when customers send / receive data at different times. With a large number of customers, the survey time should be longer. For real-time data exchange, the number of clients should be the smallest. While the device has some drawbacks, but I think it can be solved.
The client utility for managing, reading and sending data works in both Linux and Windows, but so far, unfortunately, compilation is required to tune the received data. For convenience of setting and debugging through the utility, you can change the channel, speed and enable / disable hardware confirmation, work directly with the radio module's registers.
The device can be used for wireless sensors or control in smart home systems.
By the way, earlier, a variant of the wireless humidity and temperature sensors based on the attiny13 at a frequency of 315 or 433 MHz was developed and tested, but this is another topic.
RS232-USB
Based on the USBasp programmer, you can create an RS232-USB adapter device based on the
cdc-232 project.
Suitable for programming Arduino boards that do not have an FT232RL chip or another usb-uart converter.
PIO-USB
The 6 pins that are connected to the programmer connector can be used as normal PIO pins, for “jerking” with LEDs and relyushki, as well as reading the logical state of the port. In the archive at the end of the article there is my version of PIO-USB, which also allows you to read the humidity sensor DHT11 / DHT22, as well as broadcast the code to control sockets / chandeliers, if you connect the radio at 433/315 MHz. A new version is planned, in which the number of connected humidity sensors will increase and bugs will be fixed.
DS18B20-USB
The programmer can be “taught” to work with several DS18B20 temperature sensors. For example, use the
USBTemp project.
There are other options for the implementation of the scheme and firmware devices, as well as integration with PIO-USB.
Unfortunately, due to the size of the firmware download is not possible via USBaspLoader.
I2c-usb
The device allows you to connect almost any i2c device to a computer. Tested on both Linux and Windows XP. The firmware is based on the well-known
i2c tiny usb project.
My examples of using the device:
Reading pressure sensor BMP085.
Chip control by the port expander MCP23017, thereby obtaining almost the same PIO on the computer.
Mass applications: EEPROM memory programming, reading specific specific sensors, FM receiver control.
Of course, this is by no means all the options for using a programmer in non-standard operation.
All source codes of third-party projects can be found on their official sites. In the archive at the end of the article there are firmware that are adapted to the conclusions of the USBasp board.
Archive with firmware:
usbasp.zip
UPD: Another use of USBasp in the article
"Programming nRF24LE1 via Raspberry PI and USBasp" .