INAV jumped over the bench

Let's say I have almost a good news about sonar support in INAV: yesterday I flew terrain following mode with experimental INAV code. And did not crashed when shooting video below. I did crashed next code version, but that is only a minor detail, right?

  1. When shooting that video I did not touched throttle stick. Altitude control was 100% automatic
  2. It is US-100, not HC-SR04 ultrasonic rangefinder!
  3. US-100 was connected to Omnibus F4 Pro using experimental I2C interface with ATtiny85
  4. If you want to try it, here is the code. But be prepared to crash 🙂

Read More

GPS Racer: worklog #8 – sonar test platform

I honestly admit, that my 6″ quad (codename GPS Racer) was never very pretty. It was just ugly with that GPS tower on the front. Today it got even uglier: I’ve equipped it with HC-SR04 sonar connected via I2C bus (ATtiny85 to the rescue).

Why, you might ask, have I done something so useless? Answer is simple: to make it less useless. There are at least few problems with sonar and modern flight controllers. First of all, most new boards does not have connections for it. Second of all, it does not work reliably.

HC-SR04 test platform for INAV

It just don’t. It was no unreliable that INAV, for example, disabled it for some time completely. Right now it is back, but used only during landing on multirotors. No terrain following or anything like that. Continue reading “GPS Racer: worklog #8 – sonar test platform” »

Read More

ATtiny85 Light Sensor – I2C slave device

I love AVR ATtinyx5 series microcontrollers. They are cheap, easy to use, they can be programmed just like Arduinos and comparing to their size they offer great features. For example, they can be used as remote analog to digital converters connected to master device using I2C bus.

Background: few year ago I've build a weather station based on Raspberry Pi. It collects various data and displays them on dedicated web page and Android app. Every few months I try to add a new sensor to it. Last time it was a daylight sensor. Raspberry Pi does not offer ADC inputs and I has few ATtiny85 on hand that time. One to another, few hours later: photoresistor based daylight meter sensor connected via I2C bus.

ATtiny85 as light sensor with I2C bus

Electric assembly is pretty simple: ATtiny85 directly connected to Raspberry Pi via I2C, photoresistor with 10kOhm pull down connected to ATtiny85 and signal LED.

attiny85 i2c slave light sensor with photoresistor

Code driving this rig is also pretty simple: watchdog timer wakes up ATtiny every few minutes, measures voltage, filters it and stores in memory. Every time read operation is requested, last filtered ADC value (10 bits as 2 bytes).

I2C support is provided by TinyWireS library that configures USI as I2C slave.

/**
 * This function is executed when there is a request to read sensor
 * To get data, 2 reads of 8 bits are required
 * First requests send 8 older bits of 16bit unsigned int
 * Second request send 8 lower bytes
 * Measurement is executed when request for first batch of data is requested
 */
void requestEvent()
{  
  TinyWireS.send(i2c_regs[reg_position]);

  reg_position++;
  if (reg_position >= reg_size)
  {
      reg_position = 0;
  }
}

/*
 * Setup I2C
 */
TinyWireS.begin(I2C_SLAVE_ADDRESS);
TinyWireS.onRequest(requestEvent); //Set I2C read event handler

Example code to read from device might look like this:

Wire.requestFrom(0x13, 2);    // request 2 bytes from slave device #0x13

int i =0;
unsigned int readout = 0;

while (Wire.available()) { // slave may send less than requested
byte c = Wire.read(); // receive a byte as character

if (i == 0) {
    readout = c;
} else {
    readout = readout << 8;
    readout = readout + c;
}

i++;
}

Serial.print(readout);

Full source code is available on GitHub and my Weather Station with almost a year of light level history is available here.

Read More

Programming ATtiny85 and ATtiny45 with Arduino IDE

What is ATtiny

ATtiny is a fimily of microcontrollers by Atmel, the same company that provides ATmega series used widely in “real” Arduinos. Comparing to ATmega, ATtinys are much simpler, smaller (usually), with less features. But also cheaper, easier to connect, using less energy, and trust me, in many many cases you do not need 32kB of flash memory. If, for example, you want to build a device that will beep every 10 minutes which microcontroller would you use: huge DIP-28 ATmega328P from Arduino UNO R3 or small DIP-8 ATtiny25 that ususes way less power and costs around 1EUR? I would use ATtiny.

ATtiny85 as light sensor with I2C bus

There are many microcontrollers in ATtiny family. In this tutorial and all future in this series I will concentrate on ATtiny85 with 8kB of flash memory. There are 2 simpler versions of it: ATtiny25 and ATtiny45 with respectively 2kB and 4kB of flash, but price difference between them is so small, that I see no point of trying to use them. When buoght from China, it might be even possible to buy ATtiny85 cheaper than its smaller brothers. Continue reading “Programming ATtiny85 and ATtiny45 with Arduino IDE” »

Read More