Wednesday, 30 November 2011

Wednesday, 9 November 2011

Thursday, 26 May 2011

Arduino analog Clock

Continuing the clock theme, this one uses the marvelous TVOut library to do (admittedly grainy) analog clock .

//start "sketch"
#include <TVout.h>
#include "Wire.h"
//#include <pollserial.h>
#include <fontALL.h>

TVout TV;
//pollserial pserial;

#define DS1307_I2C_ADDRESS 0x68 // This is the I2C address
// Global Variables
long previousMillis = 0; // will store last time time was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
long interval = 200;
int tvx,tvy,tvradius,x2,y2,x3,y3;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

// Gets the date and time from the ds1307 and prints result
void getDateDs1307()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0x00);
Wire.endTransmission();

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

// A few of these need masks because certain bits are control bits
second = bcdToDec(Wire.receive() & 0x7f);
minute = bcdToDec(Wire.receive());
hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(Wire.receive());
dayOfMonth = bcdToDec(Wire.receive());
month = bcdToDec(Wire.receive());
year = bcdToDec(Wire.receive());

}


void printTime()
{
TV.set_cursor(0,0);
TV.print( char( hour/10 + 0x30) );
TV.print( char( hour%10 + 0x30) );
TV.print(":");
TV.print( char(minute/10 + 0x30));
TV.print( char(minute%10 + 0x30));
TV.print(":");
TV.print(char (second/10+0x30));
TV.print(char (second%10+0x30));


TV.set_cursor(8,9);
TV.print(char(dayOfMonth/10+0x30));
TV.print(char(dayOfMonth%10+0x30));
TV.print("/");
TV.print(char(month/10+0x30));
TV.print(char(month%10+0x30));
TV.set_cursor(10,18);
TV.print("20");
TV.print(char(year/10+0x30));
TV.print(char(year%10+0x30));

TV.draw_circle(tvx,tvy,tvradius-5,BLACK,BLACK);

float angle = second*6 ;
angle=(angle/57.29577951) ; //Convert degrees to radians
x3=(tvx+(sin(angle)*(tvradius-6)));
y3=(tvy-(cos(angle)*(tvradius-6)));
TV.draw_line(tvx,tvy,x3,y3,WHITE);
angle = minute * 6 ;
angle=(angle/57.29577951) ; //Convert degrees to radians
x3=(tvx+(sin(angle)*(tvradius-11)));
y3=(tvy-(cos(angle)*(tvradius-11)));
TV.draw_line(tvx,tvy,x3,y3,WHITE);
angle = hour * 30 + int((minute / 12) * 6 ) ;
angle=(angle/57.29577951) ; //Convert degrees to radians
x3=(tvx+(sin(angle)*(tvradius-15)));
y3=(tvy-(cos(angle)*(tvradius-15)));
TV.draw_line(tvx,tvy,x3,y3,WHITE);
}


void setup() {
Wire.begin();
getDateDs1307() ;
//TV.begin(_NTSC,184,72);
//the circle didn't look very round with 184,72
TV.begin(_NTSC,150,71);
TV.select_font(font6x8);
TV.clear_screen();
//TV.println("TV Clock");
tvx= TV.hres()/2;
tvy=TV.vres()/2;
tvradius=TV.vres()/2 ;
//clock face
TV.draw_circle(tvx,tvy,tvradius,WHITE);
//hour ticks
for( int z=0; z < 360;z= z + 30 ){
//Begin at 0° and stop at 360°
float angle = z ;
angle=(angle/57.29577951) ; //Convert degrees to radians
x2=(tvx+(sin(angle)*tvradius));
y2=(tvy-(cos(angle)*tvradius));
x3=(tvx+(sin(angle)*(tvradius-5)));
y3=(tvy-(cos(angle)*(tvradius-5)));

TV.draw_line(x2,y2,x3,y3,WHITE);
}
//TV.set_hbi_hook(pserial.begin(57600));
}

void loop() {
// if (pserial.available()) {
// TV.print((char)pserial.read());
// }

// other processing here maybe

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {
// save the last time you printed and updated

previousMillis = currentMillis;
TV.delay(1);
printTime();
//read RTC
getDateDs1307() ;
}


}

//end sketch
Once again just a clock, blocky but readable :

Arduino LCD Clock

Using the Wire library to read a DS1307 RTC chip (I used this one from Seeed Studio and bits of the example code ) and the LCD3wire library to implement, what is almost the "hello world" of arduino projects, a digital clock. The LCD3wire example uses a 4094 shift register, my parts box only had a 74HC595 so the connections are a little different:





















74HC595LCDArduinopower
14

25

36

414

513

612

711

8

gnd
9


10

+ve
11
4 (clk)
12
2 (strobe)
13

gnd
14
8 (data)
15


16

+ve

1
gnd

2
+ve

3
2.2K to gnd

//the "sketch"
// Example use of LCD3Wire and Wire library
// to read time from RTC and display on LCD

#include <LCD3Wire.h>
#include "Wire.h"
// Arduino pins
#define LCD_LINES 2 // number of lines in your display
#define DOUT_PIN 8 // Dout pin
#define CLK_PIN 4 // Clock pin
#define STR_PIN 2 // Strobe pin

#define DS1307_I2C_ADDRESS 0x68

long previousMillis = 0; // will store last time time was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
long interval = 200;

//create object to control an LCD.
LCD3Wire lcd = LCD3Wire(LCD_LINES, DOUT_PIN, STR_PIN, CLK_PIN);
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

// Gets the date and time from the ds1307 and prints result
void getDateDs1307()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0x00);
Wire.endTransmission();

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

// A few of these need masks because certain bits are control bits
second = bcdToDec(Wire.receive() & 0x7f);
minute = bcdToDec(Wire.receive());
hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(Wire.receive());
dayOfMonth = bcdToDec(Wire.receive());
month = bcdToDec(Wire.receive());
year = bcdToDec(Wire.receive());

}

void printTime()
{
lcd.cursorTo(1, 4); //line=1, x=4.
lcd.print( char( hour/10 + 0x30) );
lcd.print( char( hour%10 + 0x30) );
lcd.print(':');
lcd.print( char(minute/10 + 0x30));
lcd.print( char(minute%10 + 0x30));
lcd.print(':');
lcd.print(char (second/10+0x30));
lcd.print(char (second%10+0x30));

lcd.cursorTo(2, 3); //line=2, x=3.
lcd.print(char(dayOfMonth/10+0x30));
lcd.print(char(dayOfMonth%10+0x30));
lcd.print('/');
lcd.print(char(month/10+0x30));
lcd.print(char(month%10+0x30));
lcd.printIn("/20");
lcd.print(char(year/10+0x30));
lcd.print(char(year%10+0x30));
}

void setup() {
Wire.begin();
getDateDs1307() ;
lcd.init();
lcd.clear();

}

void loop() {

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {
// save the last time you printed and updated
previousMillis = currentMillis;
printTime();
//read RTC
getDateDs1307() ;
}
}
//end sketch

The result as expected (just a clock :-) ):


Wednesday, 18 May 2011

Android tweeting with python tweepy and sl4a

my sweetheart bought me some cute android toys, thanks dear(my sweetheart gave me this cute android toy )

Jeff Miller's blog has an easy how-to tweet using Joshua Roesslein's tweepy module for python. You can run this on your computer (for ease of editing) to generate the access and consumer keys and then do stuff with SL4A on an android phone. The linux-mag.com tutorial link is using the previously available Basic Authentication, the tweepy module does all the heavy lifting to use Oauth (my previous caveats about implementing on lower spec platforms remain) instead. To use make a tweepy directory under sl4a/scripts and copy the *.py out of the tweepy egg or tgz.

The following reads your friends timeline into androids notification bar
#!/usr/bin/env python

import sys
import tweepy
import android
droid=android.Android()

CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'
ACCESS_KEY = 'paste your Access Key here'
ACCESS_SECRET = 'paste your Access Secret here'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

for tweet in friend_tweets:
droid.notify(tweet.author.name,tweet.text)

To send a tweet ( something like this) :
#!/usr/bin/env python

import sys
import tweepy
import android
droid=android.Android()

CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'
ACCESS_KEY = 'paste your Access Key here'
ACCESS_SECRET = 'paste your Access Secret here'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

tweet = droid.dialogGetInput('Twitter', 'Type your tweet here :').result
api.update_status(tweet)


Nintendo


Brick Nintendo before they brick you!

Wednesday, 27 April 2011

boxes on tellymate

Thomas Jensen's boxes
"... draws any
kind of boxes
around your text!"

add these lines to the config file to use the Code page 437 line characters on the Tellymate

#===========================================
BOX tellymateLine
sample
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ tellymateLine ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

ends
shapes {
nw ("Ú") n ("Ä") ne ("¿")
w ("³") e ("³")
sw ("À") s ("Ä") se ("Ù")
}
elastic (n,s,e,w)
END tellymateLine

BOX tellymateDLine
sample
ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
º tellymareDline º
ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ

ends
shapes {
nw ("É") n ("Í") ne ("»")
w ("º") e ("º")
sw ("È") s ("Í") se ("¼")
}
elastic (n,s,e,w)
END tellymateDLine

Saturday, 16 April 2011

android tablet update problem

If you (like me) have had a "NAND not supported" error trying to update a cheap WM8505 Android tablet (motherboard is wms8105c like this one ) it's because, when you look inside, there is no NAND on the CPU daughter-board. It has a naked USB stick wired up. Tipstir has update ROMs here that fix the problem , WMT212_105_M3CSL_V10_script.7z works good.

Tuesday, 12 April 2011

Man in Space

It's fifty years since Yuri Gagarin was launched into history as the First Man in Space. Celebrate.

Wednesday, 6 April 2011

Zero Carbon AU

Melbourne University have produced "A ten year roadmap for 100% renewable energy "
http://www.zerocarbonplan.org/

it looks feasible and affordable, so the question (for our politicians ) is why aren't we doing it ?

Tellymate works good

I bought a TTL Tellymate kit from Batsocks to hook to my Bifferboard, with a simple transistor to invert the RS232 it works good. It's like cool retro ascii from days gone by.
I whipped up a quick bash script to interact with it :
#=============================
#!/bin/bash
export TERM=vt52
PORT=/dev/ttyS0
ESC="\x1b"

function dohelp {
echo -en "tm \n -c clear screen\n -q print diagnostic info\n -b big letter banner \n -e program to run\n"
}

function cls {
echo -en $ESC"E" >$PORT
}
while getopts "b:cqe:h" flag
do
case "$flag" in
c) CLS="yes" ;;
q) Q="yes" ;;
b) BIGTEXT="$OPTARG" ;;
e) PROG=$OPTARG ;;
h) dohelp;;
esac
done
if [ "$PROG" != "" ] ;then savestate ;fi
if [ $CLS ]; then cls;fi
if [ $Q ];then
echo -en $ESC"Q" >$PORT
fi

if [ "$BIGTEXT" != "" ]; then
echo -en $ESC"_4"$BIGTEXT"\n"$ESC"_5"$BIGTEXT"\n" >$PORT
fi
#needs more functions to do x and y pos etc..
#====================================================

along with figlet and the fold and other linux text utilities it was easy to do stuff :
eg.
tm -c -b TESTING -e "figlet -c -w38 Telly Mate test"

tm -c -e "figlet -c -w38 `date`"
(hard to take good photos of lcd but )

Reading

Foucault's Pendulum by Umberto Eco

Tuesday, 5 April 2011

Wrong

In this (via BSNYC) notionally satirical piece in the WSJ P.J O'Rourke quips "Search plazas, parks and city squares the world over and you won't fine[sic] a single statue of a national hero riding a bike."
Completely wrong, Rochester has this fine statue of Sir Hubert Opperman .

Friday, 14 January 2011

Sunday, 2 January 2011