Sunday, December 17, 2017

PDC1211: a simple clock sketch




Hello! Upon request I've written a very simple clock sketch. It uses the PDC1211 library for that I wrote for a 7 segments lcd with 12 digits and 1 row. In its own turn this library is based on the HT1621 and LiquidCrystal7S libraries. Please see them all for more informations. Enjoy!

The sketch
It is assumed that you use a PDC1211 module. The clock is pretty precise but to be more precise I've added some compensation to correct the millis lost during the lcd update operations. The compensation has been measure on an Arduino Uno module, if you use a different module, please recompute the compensation.

Indeed, an update is performed every 500 millis. If the variable Blink is true then only the two '-' symbols are updated. Otherwise, a second is passed and all the time variables are updated suitably. The first phase costs about 5 millis, the second 9 millis. If the updating period is changed, then don't forget to measure and change those values.

See here for more informations about pin connections.

/**
 * \file clock.ino
 * \brief Simple clock for the PDC1211 library.
 * \author Enrico Formenti
 * \date 12 17 2017
 * \version 1.0
 * \copyright BSD license, check the License page on the blog for more information. All this text must be
 *  included in any redistribution.
 *  <br><br>
 *  See macduino.blogspot.com for more details.
 */

#include "PDC1211.h"

#define SS 2
#define RW 3
#define DATA 4

PDC1211 lcd(SS,RW,DATA);


uint8_t seconds = 55;
uint8_t minutes = 59;
uint8_t hours = 23;

bool hasToUpdateHours = true;
bool hasToUpdateMinutes = true;
bool Blink = false;
uint16_t compensation = 0;


void setup() {
    lcd.begin();
}

void loop() {

    delay(500);
    if(Blink) {
        lcd.setCursor(2,0);
        lcd.print(" ");
        lcd.setCursor(5,0);
        lcd.print(" ");
        compensation += 5;

    }
    else
    {
        lcd.home();
        ++seconds;
        if(compensation>=1000) {
            ++seconds;
            compensation = 0;
        }
        if(seconds==60) {
            seconds = 0;
            ++minutes;
            hasToUpdateMinutes = true;
        }
        if(minutes==60) {
            minutes = 0;
            ++hours;
            hasToUpdateHours = true;
        }
        if(hours == 24)
            hours=0;
        if(hasToUpdateHours) {
            if(hours<10)
                lcd.print('0');
            lcd.print(hours);
        }
        else
            lcd.setCursor((uint8_t)2,(uint8_t)0);

        lcd.print("-");

        if(minutes<10)
            lcd.print('0');
        if(hasToUpdateMinutes)
            lcd.print(minutes);
        else
            lcd.setCursor((uint8_t)5,(uint8_t)0);
      
        lcd.print("-");
  
        if(seconds<10)
            lcd.print('0');
        lcd.print(seconds);
  
        hasToUpdateHours = false;
        hasToUpdateMinutes = false;
        compensation += 9;
    }
    Blink ^= true;
}

Monday, June 6, 2016

ASOM (sensor library): now supporting MCP7941X




Another great contribution of Daniele Ratti (aka ilFuria) who added support for SRAM and EEPROM for MCP7941X. Hope it may help. Many thanks to him.


The new version of the sensor library can be downloaded from GitHub here.

Some other developments are in preparation (September 2016). Please come back soon!

Enjoy!

Sunday, May 31, 2015

ASOM (sensor library): update and bug fixes




Many many thanks to Daniele Ratti who made a lot of improvements to the section concerning the RTC module. He made also some bug fixes and tested all the procedures.


The new version of the sensor library can be downloaded from GitHub here.

Enjoy!

Friday, January 30, 2015

A spinning top for your LCD





Sometimes we need to wait for the end of a task or for an event to occur and at the same time to keep the user informed that the system is not hung. This is the right occasion for a spinning top!

In this post we propose a very simple one. Indeed, it is a good occasion to see how to use the character generator of the LCD and insert new character. The module that we are going to use is based on the famous Hitachi HD44780 chip. This chip has the possibility to increase its char set with 4 additional user defined chars. This easily done using the command createChar which take in input the id code for the new char (an integer between 0 and 3) and an array of 8 bytes which are interpreted as a bitmap (here we use the 5x8 charset).

What you need
  • 1x Arduino Uno
  • 1x LCD module
Just that! For more on the LCD module you can also have a look here.

Configuration
Modify the definitions of the pins to adapt to your LCD module. In order to change the speed of the spinner decrease the value of FRAMETIME. This variable control the frame rate. Indeed, frame rate is approx 1/FRAMETIME.

The sketch
/**
 * Spinning top
 *
 * \author Enrico Formenti
 * \version 1.0
 * \date 30 january 2015
 *  \copyright BSD license, check the License page on the blog for more information. All this text must be 
 *  included in any redistribution.
 *  <br><br>
 *  See macduino.blogspot.com for more details.
 */

#include <LiquidCrystal.h>

// modify the definitions below according to your LCD module
 
#define LCD_RS_PIN 7
#define LCD_ENABLE_PIN 6
#define LCD_DATA4_PIN 5
#define LCD_DATA5_PIN 4
#define LCD_DATA6_PIN 3
#define LCD_DATA7_PIN 2

LiquidCrystal lcd(LCD_RS_PIN, LCD_ENABLE_PIN, LCD_DATA4_PIN,
                  LCD_DATA5_PIN, LCD_DATA6_PIN, LCD_DATA7_PIN);


// modify the value below to change the frame rate
// framerate per second is approx 1/FRAMETIME 
#define FRAMETIME 120


// the backslash character is not in the standard char set
// of the LCD so let's redefine it

uint8_t backslash[8] = {
    0b00000,
    0b10000,
    0b01000,
    0b00100,
    0b00010,
    0b00001,
    0b00000,
    0b00000
};

// we use special character 0 here
char spinningTop[] = {'/', '-', 0, '|'};
uint8_t k;

void setup() {
  // put your setup code here, to run once:
  k = 0; // init spinner
  
  // init screen
  lcd.begin(16, 2);
  lcd.createChar(0, backslash);
  lcd.clear();
  lcd.print("Look at me... ");
}

void loop() {
  // update spinner and...
  lcd.setCursor(14,0);
  lcd.write(spinningTop[k%4]);
  k = (k+1) & 0b11;
  // ...waste some time to let user see it spinning
  delay(FRAMETIME);
}

Suggestions
Remark that our implementation of the spinner uses busy waiting. In order to avoid it one can use interrupts. However, if you decide to use interrupts, recall that they can interfere with other modules or sensors and that Arduino Uno only has two of them!

Enjoy!

Thursday, November 14, 2013

Kick-off for the sensor library




This is my first attempt in writing a library for Arduino. The idea is to write some generic class for sensors. Specialized classes will implement each particular family of sensors. I would like also to start an independent sensor identification code. To uniquely identify each sensor component so that one can implement component comparisons and so on.


Here is an example of sensor (DHT11) which I would like to support. Here is the minimal code for the Sensor class.