Category Archives: Arduino

Build a simple Webserver with Pollin AVR-NET-IO using the Arduino software stack

0. Programmer

I'm using an Arduino as ISP to flash the webserver to the AVR-NET-IO. See my previous post Dump ATMEGA32 on AVR-NET board using avrdude for how to convert the Arduino to a programmer and how to wire the connections between the Arduino (programmer) and the AVR-NET-IO. Do not connect AVR-NET-IO's own power source when it is connected to the Arduino (programmer).

1. ATmega32

The AVR-NET-IO uses the ATmega32 microcontroller about which the Arduino IDE does not know anything. Thankfully, Eric Conner has written a definition file for the ATmega32 needed by the Arduino IDE.

1.1. Download definitions from https://github.com/eaconner/ATmega32-Arduino and follow the instructions to install the mega32 variant files.

1.2. Patch the pins_arduino.h file to contain the following additional lines:

static const uint8_t SS   = 4; // D4
static const uint8_t MOSI = 5; // D5
static const uint8_t MISO = 6; // D6
static const uint8_t SCK  = 7; // D7

I have the file in the following directory:

%USERPROFILE%\Documents\Arduino\hardware\mega32\variants\mega32\pins_arduino.h

2. ENC28J60 network chip

The Pollin board also contains an ENC28J60 network chip. This cannot be addressed by the Arduino Ethernet library directly but there is a wonderful replacement library available from Norbert Truchsess at

https://github.com/ntruchsess/arduino_uip

Install the library as described in the installation instructions on the above link.

I have the library files in the following directory:

%USERPROFILE%\Documents\Arduino\libraries\UIPEthernet

e.g. the file %USERPROFILE%\Documents\Arduino\libraries\UIPEthernet\Dhcp.cpp

3. Webserver

3.1. Start Arduino IDE, open from the menu Examples / Ethernet / WebServer .

3.2. Change the include directive

#include <Ethernet.h>

to

#include <UIPEthernet.h>

4. Compile and Upload

4.1. In Arduino IDE menu select: Tools / Programmer / Arduino as ISP

4.2.  Select Tools / Board / ATmega32-External 16MHz

4.3. File / Upload using Programmer (this sometimes aborts with error message "Not int sync". Simply give it a second try.

4.4. Make sure to disconnect the Arduino (programmer) from the AVR-NET-IO before you connect AVR-NET-IO's own power source.

Read fuses of ATMEGA32 on AVR-NET-IO

Same configuration as described in the previous post Dump ATMEGA32 on AVR-NET board using avrdude. Then

bin\avrdude.exe -C etc\avrdude.conf -c avrisp -p ATMEGA32 -P com4 -b 19200 -v

The output for was


avrdude.exe: Version 5.11, compiled on Sep  2 2011 at 19:38:36
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "etc\avrdude.conf"

             Using Port                    : com4
             Using Programmer              : avrisp
             Overriding Baud Rate          : 19200
             AVR Part                      : ATMEGA32
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PA0
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
               flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
               lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
               lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
               calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

             Programmer Type : STK500
             Description     : Atmel AVR ISP
             Hardware Version: 2
             Firmware Version: 1.18
             Topcard         : Unknown
             Vtarget         : 0.0 V
             Varef           : 0.0 V
             Oscillator      : Off
             SCK period      : 0.1 us

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.06s

avrdude.exe: Device signature = 0x1e9502
avrdude.exe: safemode: lfuse reads as FF
avrdude.exe: safemode: hfuse reads as CA
avrdude.exe: current erase-rewrite cycle count is -1062731548 (if being tracked)

avrdude.exe: safemode: lfuse reads as FF
avrdude.exe: safemode: hfuse reads as CA
avrdude.exe: safemode: Fuses OK

avrdude.exe done.  Thank you.

Use the Engbedded Atmel AVR® Fuse Calculator to interpret the values

lfuse reads as FF
hfuse reads as CA

from the output above.

Clock source

CKSEL3 [ ]
CKSEL2 [ ]
CKSEL1 [ ]
CKSEL0 [ ]

means External crystal

Boot

BOOTSZ1 [X]
BOOTSZ0 [ ]

means Boot size 1024 words

BOOTRST [X]

means program counter points to bootloader (instead of 0xC00) after reset

My visit at the Easterhegg 2014 in Stuttgart, Germany

Interesting things I've learned at the Easterhegg in Stuggart. I've been there Saturday and Sunday only.

Day 2

  • dawanda used cross device responsive tables
  • Better presentations with a workshop by Dirk Haun. We heard about the Rule of Thirds, no bullet points, images from http://freeimages.com, http://www.flickr.com/creativecommons/, ...
  • ImageMagick can create 3D software boxes from images.
  • Adafruit sells LED strips that can be used by Arduino easily
  • palava.tv uses WebRTC and an open source central signaling server to enable peer to peer (P2P) video and audio chats and conferences. Soon the server might be available in an SD card image for the Raspberry Pi.

Day 3

  • AYAB - all yarns are beautiful: Project to connect old Brother KH-910 and KH-930 knitting machines to computers to knit images of 200px width (and arbitrary height). Project located in Munich (MuCCC). Uses Arduino, Python, and (future work) PyQt. https://wiki.muc.ccc.de/ayab, http://www.ayab-knitting.com/
  • A few ideas about CNC machining, e.g. Shapeoko, importance of good common ground, ...
  • Spice up your presentations with reveal.js (e.g. http://palavatv.github.io/talk-webmontag/)and use Unicode characters, e.g. for :poop:. See fileformat.info for a detailed list. I have to learn about Emojis/Gemojis...
  • The version of a framework used in Java can be obtained by analysing its stack trace, especially the classname together with the line numbers. Maybe you should take care that your web server never prints that trace in case of errors.
  • Do not accept jobs that force you to make overtime hours that will be lost at the end of the month.
  • Baozi might be interesting to cook myself. Didn't have the time to go to the workshop.
  • A few introducery things about CAN and CANopen.
  • DMX, the protocol used for event technology (Veranstaltungstechnik) is very simple and can be used from Arduino, too. Maybe script a few cool effects using DMX isn't very hard. Just send a reset, a NULL, a node id and a value between 0 and 511 and your light starts to shine proportional - http://eh14.easterhegg.eu/pages/fahrplan/events/5772.html
  • A few very interesting details about how to sell your own electronics.
  • Weller PU 81 soldering stations are very expensive
  • There are quadrocopters that can carry 4kg

My first stepper experiment

I got my first stepper running with Arduino. I found an old pair of steppers in one of the boxes where I keep such things for years now, (»maybe one needs them one day«).

This is the stepper motor pair I have:

2014-01-25 16.52.53

It is a 6 wire unipolar motor: It seems as if bipolar steppers have 4 wires, unipolar ones 5 or 6 wires.

Now I had to find out what are the common ground wires. Here I found

...one way to distinguish common wire from a coil-end wire is by measuring the resistance. Resistance between common wire and coil-end wire is always half of what it is between coil-end and coil-end wires. This is due to the fact that there is actually twice the length of coil between the ends and only half from center (common wire) to the end.

Testing the resistance with an ohmmeter the two center wires could be identified as the common wires.

Unfortunatelly, I only had a L293D step motor driver chip which is meant for bipolar motors. But as it turns out, this is not a problem when you connect the 2 common wires

The MotorKnob tutorial on arduino.cc (big picture of the breadboard layout) shows how to connect a bipolar motor to the Arduino. When you don't connect the common wire, the unipolar motor works with the L293D driver.

Connecting an Arduino with the Raspberry Pi via I2C

Today, I tried connecting my Raspberry Pi to an Arduino via I2C bus following roughly the guide from Oscar Liang.

According to the GPIO pinout, we have to connect pins 3 and 5 of Pi's GPIO port to Arduino's A4 and A5 pins.

First, the revision of the Raspberry Pi is important to determine which I2C port to use. Output of /proc/cpuinfo is

$ cat /proc/cpuinfo
Processor       : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 697.95
Features        : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2708
Revision        : 0002
Serial          : xxx

That means, that according to this list ...

'0002' => 'Model B Revision 1.0',
'0003' => 'Model B Revision 1.0 + Fuses mod and D14 removed',
'0004' => 'Model B Revision 2.0 256MB', (Sony)
'0005' => 'Model B Revision 2.0 256MB', (Qisda)
'0006' => 'Model B Revision 2.0 256MB', (Egoman)
'0007' => 'Model A Revision 2.0 256MB', (Egoman)
'0008' => 'Model A Revision 2.0 256MB', (Sony)
'0009' => 'Model A Revision 2.0 256MB', (Qisda)
'000d' => 'Model B Revision 2.0 512MB', (Egoman)
'000e' => 'Model B Revision 2.0 512MB', (Sony)
'000f' => 'Model B Revision 2.0 512MB', (Qisda)

...I have a Model B Revision 1.0 and therefore according to this overview I have to use -y 0 in the i2c commands following.

After installing the i2c-tools

$ sudo apt-get install i2c-tools

we can try to find the I2C device Arduino:

$ /usr/sbin/i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- 04 -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Now write a 1 to Arduino with:

/usr/sbin/i2cset -y 0x00 0x04 1

On the Arduino I installed a Wire program from Arduino's examples.