Thursday, December 27, 2012

Measure light (lux) with LDR on AVR Atmega using LDR library 01

A photoresistor or light dependent resistor (LDR) is a resistor whose resistance decreases with increasing incident light intensity; in other words, it exhibits photoconductivity.
The lux (symbol: lx) is the SI unit of illuminance and luminous emittance, measuring luminous flux per unit area.


This library implements a way to estimate lux given a LDR resistance value read from an ADC input pin of an AVR Atmega.
The estimation is based on this formula:
lux = A*((R/B)^C)
where R is the LDR resistance.
An Excel spreadsheet is provided to help the estimation of A, B and C values. You have to read lux values using a calibrated luxmeter, and the R values of your LDR, write it down on the Excel sheet, and estimate A, B and C, power regression can help you estimating values.

Code

Notes
  • read risk disclaimer
  • excuse my bad english

Friday, December 21, 2012

Reading temperature on AVR Atmega using a thermistor with NTCtemp library 02

This library is an update to ntctemp 01, look here for info: http://davidegironi.blogspot.it/2012/06/ntctemp-simple-avr-library-to-read.html

A thermistor is a type of resistor whose resistance varies significantly with temperature, more so than in standard resistors.


NTCtemp is a simple AVR library to read temperature from a thermistor connected to an atmega micro.
The library implements three models convert adc value read from analog input to temperature:
  • Steinhart-Hart Thermistor Equation
  • Beta Model Equation
  • Lookup Table estimation
A digital iir filter is implemented to remove unwanted reading errors.

For Steinhart-Hart and Beta model equation, look at the previous article.
This version of the library implements a Lookup Table estimation method, which can be usefull if you do not want to include log function, and mantain you hex smaller.

To helper are provided:
  • the beta estimation helper
  • the make lookup table helper
The beta estimation helper, helps you to estimate beta value of unknown thermistor.
It is almost the same provided in the reprap wiki page here: http://reprap.org/wiki/MeasuringThermistorBeta. A readme file with instruction is provided with the spreadsheet of the helper

The make lookup table helper is a spreadsheet which generate the lookup table according to preselected values. Estimation is done using the Beta Model Equation: temperature (Celsius) = beta / ( beta / tref + ln ( R / rref ) ) - 273.15

Each element in the table is a temperature for a given ADC value.
Given the ADC value of the connected thermistor, we can measure the temperature using the lookup table.
Because we know the ADC value for the first element of the table, and the interval between values, we can select the nearest lower index for any given ADC.
Then we can select the upper and lower temperature values for the selected index.
On those values we do interpolation to obtain a correct temperature value.
We must calculate the inverval step, indicates the position between upper and lower index, of the current adc value.
Then we can do interpolation of values.
intervalstep = currentadcvalue-minindex
t = lowertemp + ((uppertemp-lowertemp)/lookupadcstep) * (intervalstep);

Es. given a table which contains temperature for ADC: ..201,211,221.. temp: ..-7.21, -5.97, -4.75, the current ADC is 214, the lower index should be 211, and upper 221, so lower and upper temperature is -5,97 and -4.75. intervalstep is 214-211 = 3. t = -5.97 + (-4.75- -5.97)/10 * 3 = -5.604. Which is near to the value obtained using the beta model equation (-5.599). 0.005 degree of error.

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.


Code

Notes
  • read risk disclaimer
  • excuse my bad english


Monday, December 17, 2012

Reading Temperature and Humidity on AVR Atmega using DHT11 library 01

updated version: http://davidegironi.blogspot.it/2013/02/reading-temperature-and-humidity-on-avr.html

The DHT11 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed).


This library use DHT11 sensor to read temperature and humidity on on Atmega micro.
Setup the data port connected to the micro pin, and call the function to get humidity and / or temperature.

DHT11
  • Power supply 3.5-5.5V DC
  • Measuring range Humidity: 20-90%RH
  • Measuring range Temperature: 0-50 Celsius.

Setup parameter are stored in file dht11.h

Code

Notes
  • read risk disclaimer
  • excuse my bad english

Saturday, December 8, 2012

Drive multiple (up to 12) stepper motors on Atmega using 74hc595 and "stepper04multi" library 01

A stepper motor is a brushless DC electric motor that divides a full rotation into a number of equal steps.



Stepper04multi is an AVR Atmega stepper motor library.
Stepper04multi can run multiple stepper motor (up to 12) having different direction, type and speed with a precision of 256us per step @8Mhz.
Setup parameters is stored in stepper04multi.h files.
Stepper04multi use 74hc595 ics to expands the number of micro ports.



This libray drives many stepper motors, to drive motors, every step is computed during timer interrupt. If you are running many tasks on the micro, your should check that motor step happens at a correct speed. If not, you have to increase the micro frequency, or reduce the number to motors to run. As example, on Atmega8 less than 3 motors runs without timing problem at 1Mhz.
Setup parameters is stored in stepper04multi.h files.

Pictures and video shows only two motors connected, cause i've only 2, but up to 12 can be connected, i've checked output pin using a logical analyzer, and results are fine.
The picture below refers to one motor output, during the sample motor velocity was 1280us, as you see the step is 1.250ms = 1250us, which is close to the requested velocity.


This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz (fuse LF: 0xE4, HF: 0xD9)


Code

Notes
  • read risk disclaimer
  • excuse my bad english

Tuesday, December 4, 2012

Drive up to 3 stepper motors on Atmega using "stepper02" library 01

A stepper motor is a brushless DC electric motor that divides a full rotation into a number of equal steps.



Stepper02 is an AVR Atmega stepper motor library that can drive up to 3 motors having different direction, type and speed with a precision of 256us per step @8Mhz.
To drive a motors connect an ic driver between atmega pin and motor.
Setup parameters is stored in stepper02.h files.



This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz (fuse LF: 0xE4, HF: 0xD9)

Code

Notes
  • read risk disclaimer
  • excuse my bad english