Arduino Uno & I2C peripherals

Introduction

This page describes my experiments with Arduino Uno and peripherals

Learning PCF8583, the I²C RTC

RTC Schema

PCF8583external link is RTC clock/calendar with alarm functionality. The device has 256x8-bits of RAM. On base PCB, I placed two ones - first used for clock/calendar and daily alarm, second used as timer for updating status LED's independently from rest of software.

Both RTC's are backed up with CR232 baterry. Arduino Uno have only two interrupt inputs:


Software

For driving this device, there are some libraries available, but no ones fit's to me. I decided join two ones and make it suitable for my needs. You can download it.

Here is most of my source code for RTC's. Note, that interrupt handlers only sets global variable, that serves as flags. Those flags are checked in main loop and here is required functionality. It's not good idea do some complex work in interrupt handler routine (e.g. I²C communication), because it may conflict with main code.

Note, that in routines handleInterrupt0(), handleInterrupt1(), alarm must be restarted using appropriate function.

Daily alarm test

Wake up me every day at 17:54, when I watch weather forecast at TV:

Weekday alarm test

Following code trigger daily alarm in next minute, but only in Tuesday:

Dated alarm test

Following code trigger alarm at specified date-time:

Timer alarm test

Following code trigger timer alarm every 5 seconds:

You can use other units, as defined in PCF8583.h : TIMER_HUNDRS_OF_A_SEC, TIMER_SECONDS, TIMER_MINUTES, TIMER_HOURS, TIMER_DAYS

Learning PCF8574, the I²C 8-bit expander

Remote Alarm Schema

PCF8574external link is the I²C 8-bit expander, that allows give another I/O ports, when Arduino ones is consumed. This chip is available in two variants: The PCF8574P has an I²C address starting with 0100 but the PCF8574AP has an address starting with 0111. This means that PCF8574P uses address range 0×20 - 0×27, PCF8574AP uses address range 0×38 - 0×3F.

For playing with it, I made simple circuit with PCF8574AP driving 8 FLUX LED's using ULN2803A.


Testing sketch

This sketch demonstrates bit rotations with sending data to PCF8574 driving LED's:

Another sample:

Learning PCF8591external link , the I²C 8-bit A/D and D/A converter

DAC

PCF8591 has one 8-bit DAC. This sketch shows triangle wave on DAC output:

triangle wave on DAC output

Curve tracer

Introduction

I create simple curve tracer, inspired by this pageexternal link. Instead of using Arduino PWM outputs, two PCF8591 DAC's are employed.

Schema, function description

Curve tracer schema

For each traced curve, DAC #2 sets base (or gate) voltage, defined in array:

Then sawtooth wave is set as collector voltage by ADC #1 and Uce and Ice are measured by Arduino ADC's. PCF8591 ADC is not used, because it's only 8bit, Arduino have 10 bit ADC's.

Software

Tracer software is divided to two parts: On Arduino is running sketch that drive DAC's and make measurement. Measured values are sended to Serial line to PC (trough USB connection), where run Processingexternal link sketch that draws chart. Both sketch are based on Don Sauer's work, I added some functionality, made changes to use PCF8591 and borrow some code for keyboard and LCD support from alarm project.

Running Processing sketch

Note, that I use Processing 2.0.3 - Win 32, because Serial not supported in 64 bit version. Also note that Processing 2.1 have Serial functionality buggy - Serial.flush(); function not works for me.

28BYJ-48 – 5V Stepper Motor with ULN2003 driver

Original Arduino Stepper library not works well with this device (because it requires 8-step controlling), so I modified it - it's compatible with original. Code is fork of original library and driving of motor is borrowed from article on Instructableexternal link

Links external link

Valid XHTML 1.0!     Creative Commons License - non commercial