Friday, December 14, 2012

Liquid level processing with OpenCV & Python

import numpy as np
import cv2
import math

cap = cv2.VideoCapture(0)

while True:
    ret, img =
    if img is None:
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 100, 120)
    lines = cv2.HoughLinesP(edges, 1, math.pi/1, 20, None, 2, 480);

    dot1 = (lines[0][0][0],lines[0][0][1])
    dot2 = (lines[0][0][2],lines[0][0][3])
    cv2.line(img, dot1, dot2, (255,0,0), 3)
    cv2.imshow("output", img)
    length = lines[0][0][1] - lines[0][0][3]
    print (length)
    key = cv2.waitKey(10)
    if key == 27:


Wednesday, December 12, 2012

Saturday, November 24, 2012

How to program ATTINY2313 with USBASP? or/and Upload Arduino firmware with USB ASP

You trying upload firmware with USBASP on attiny2313 and have errors like:
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: error: programm enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.
The problem is that the 2313's default clock (internal oscillator, CKDIV8 enabled) is way to slow for the SCK used by the USBasp by default. From this error message it seems like the current version of avrdude already adresses this problem and tries to reduce the SCK clock rate, but your USBasp's firmware doesn't support that. (thank to noah1989
fix this issue in two steps:
avrdude -p 2313 -P com13 -b 19200 -c avrisp -U flash:w:usbasp.hex
usbasp.hex download (v2009-02-28) yes, it's most recent

Also new firmware version allow you to use USBASP with Arduino 1.0.2 and 1.5 to upload Arduino bootloader.
  • manually reduce the SCK frequency by setting the "Slow SCK" jumper on the board. This schematic helps you to find it: In USBASP from China (eBay) you will not find this jumper. You need manually solder piece of wire. Like I did, see my pic for details:

Thursday, November 8, 2012

Very advanced AVR attiny2313 WAV music player. Read files from SD card / microSD / MMC.

Player controls: UART or/and One button "Select / Play" or/and binary code "Select track"

Pinouts and Switches

UART - send upper symbol "A" to start first track, "B" for second, etc... (check below for more info). To stop playback enter any other symbol.
Dir1 / Dir2 - Select directory with WAV files. Required 2 directory with names "1" and "2". Dir "1" selected by default
Select / Play - button launches a track to play. One click play first track, double click second, etc...
Select track - play track by binary code. If 0001 play first track, if 0010 play second, etc... Counting in binary

Monster - can slow (2 times) track play. The switch works "on the fly"
Helium - speeds up the track (1/3). The switch works "on the fly"
Repeat - if the switch is shorted to ground, the selected track will be forever played.

Debug LED information

The red LED flashes - no SD card or its type is not supported by the device

Red LED lights - SD card is supported and successfully initialized, but the card was not formatted in FAT16

Green LED lights - SD card is initialized successfully, locate the file system and the device is ready to play a track - waiting for the team

Green LED flashes - the device plays the track
The green goes to red, the green again - not found a track
The green briefly goes out and the green again - pressed to choose track

Debug UART information

After each successful step in the UART sends the appropriate symbol:
S - (Start) of the microcontroller peripherals initialized properly
C - (Card Init) SD card is initialized properly and supported
F - (FAT Init) FAT system is supported
1 - (No 1 Dir) no folder "1" is read from the root directory
2 - (No 2 Dir) no folder "2" will be read from the root directory
R - (Ready) the device is fully ready. Waiting for the command to start the track
In addition, each time a track is transferred to the UART capital track name.

File system and WAV file format

microSD/SD/MMC card must be formated in FAT16. 2GB maximum supported flash card size.
WAV file should be Mono with 32000Hz Sample rate and 8 Bit Depth.
In order for the unit knew what file first, second, third, etc. the first character of the file name must be uppercase letters (the rest of the name as the file extension - is ignored.)

Uploading Attiny2313 WAV player firmware in 4 steps
4. Open terminal and run next command: avrdude -c avrisp -b 19200 -P com13 -p t2313 -U lfuse:w:0xe4:m -U hfuse:w:0xdf:m -U flash:w:SDC_Talking.hex

My device photos

AVR Attiny2313 WAV player with Sparkfun FTDI attached

attiny2313 SD card WAV player

Arduino as AVRISP programmer




Credits and source code