Arduino http://concurrency.cc – Plumbing for the Arduino

http://concurrency.cc/docs/ Plumbing for the Arduino
http://concurrency.cc/download.html

// try to parallel processing on arduino like plumbing
// plumbing is more elegant,
// but its possible to do basic stuff without plumping on arduino using Alarms/Timer libs
// http://concurrency.cc/download.html

breadboard setup

in this basic example,
three LEDs are blinking..
with different on/off times,
and one button,
pushed all LEDs will be switch on


#include <Time.h>
#include <TimeAlarms.h>

// try to parallel processing on arduino like plumbing
// plumbing is more elegant,
// but its possible to do basic stuff without plumping on arduino using Alarms/Timer libs
// http://concurrency.cc/download.html

//AlarmId Alarm_A = Alarm.timerRepeat(start_every_seconds, func_name );
//AlarmId Alarm_A = Alarm.timerOnce(start_in_seconds, func_name );
//Alarm.disable(Alarm_A);
//Alarm.delay(10);

const int PinA = 8;
const int PinB = 7;
const int PinC = 13;
const int ButtonPin = 6;

int mem_A0 = 0;// memory var A0
int mem_B0 = 0;// memory var B0
int mem_C0 = 0;// memory var C0

AlarmId Alarm_A_on = Alarm.timerOnce(2, A_high ); // would be nice to have: callbacks with args, but without, i try to do something with global vars
AlarmId Alarm_B_on = Alarm.timerOnce(3, B_high );
AlarmId Alarm_C_on = Alarm.timerOnce(4, C_high );

void setup() {

Serial.begin(9600);
// initialize the digital pin as an output.
pinMode(PinA, OUTPUT);
pinMode(PinB, OUTPUT);
pinMode(PinC, OUTPUT);

pinMode(ButtonPin, INPUT); // button
digitalWrite(ButtonPin, HIGH); // use internal pull-up resistor, and button with only one cable without resistor
}

void loop() {
Alarm.delay(1); // time frame segmentation

int BUTTON_STATE = digitalRead(ButtonPin);// check every ms, for best response
if (BUTTON_STATE == LOW){
digitalWrite(PinA, HIGH);
digitalWrite(PinB, HIGH);
digitalWrite(PinC, HIGH);
}
}

void A_high(){
digitalWrite(PinA, HIGH); // set the LED on
AlarmId Alarm_A_off = Alarm.timerOnce(2, A_low );
Serial.print("mem_A0: ");Serial.println( mem_A0 );
mem_A0 = mem_A0+1;
}
void A_low(){
digitalWrite(PinA, LOW); // set the LED on
AlarmId Alarm_A_on = Alarm.timerOnce(2, A_high );
}

void B_high(){
digitalWrite(PinB, HIGH); // set the LED on
AlarmId Alarm_B_off = Alarm.timerOnce(3, B_low );
Serial.print("mem_B0: ");Serial.println( mem_B0 );
mem_B0 = mem_B0+1;
}
void B_low(){
digitalWrite(PinB, LOW); // set the LED on
AlarmId Alarm_B_on = Alarm.timerOnce(3, B_high );
}

void C_high(){
digitalWrite(PinC, HIGH); // set the LED on
AlarmId Alarm_C_off = Alarm.timerOnce(4, C_low );
Serial.print("mem_C0: ");Serial.println( mem_C0 );
mem_C0 = mem_C0+1;
}
void C_low(){
digitalWrite(PinC, LOW); // set the LED on
AlarmId Alarm_C_on = Alarm.timerOnce(3, C_high );
}

Arduino neighbourhood

Arduino neighbourhood:

http://leaflabs.com/devices/#Maple
http://www.heise.de/newsticker/meldung/ARM-Board-fuer-Arduino-Shields-1618108.html

pythonic board

python on nokia handy to steer arduino
http://www.developer.nokia.com/Community/Wiki/Communicating_with_Arduino

python on a chip, only a bit of python power
https://www.xcore.com/projects/python-chip
http://code.google.com/p/python-on-a-chip/

mini pc:
http://www.solid-run.com/products/cubox
http://www.olimex.com/dev/index.html
iMX233-OLinuXino is Industrial grade Single Board Linux computer in very compact form.
http://apc.io

PYTHON ARM-Board für Arduino-Shields

http://www.heise.de/newsticker/meldung/ARM-Board-fuer-Arduino-Shields-1618108.html
http://rascalmicro.com/ you want to buy one? sold out!

wow, a board like Arduino?
using these many available shields from arduino?
and programming not in C/C++
its complete PYTHON !!!

150,- Dollars..  that price could be ok,
hmm for that money i can use a junkyard laptop 100,-euro (lenovo with celeron)
and work with arduino… complete Logic would be programmed at laptop in python..
having more calculation power … managing image recognition, shooting webcam images etc..

i will have an eye on that piece of pythonic hardware

Arduino Read Analog with MCP3208 and LM3940

i want to track a 12 Volt battery, charging and discharging cycles (bedini project)

using voltage divider: 3 pieces of 1K resistors 1%,
min readings at 12.00V, max reading for 15V…
15V divide by 3.. each resistor gets max 5V
these 5V are the analog input for Arduino..

but Arduino Analog readings have too much fluctuations..
and are 10 bit (1024steps) only.. but 10bit should enough?
5V / 1023 = 0,00488V = 5mV  for each step

DONT FORGET EXTRA POWER WALLPUG 9V…
this stabilizes board power!!! and so the Vref for the external extra ADC MCP3208

so i looked around on arduino pages..
coming around with the SPI ADC the MCP3208 12bit(4096steps)
http://arduino.cc/playground/Code/MCP3208

i connected all pins to my ARDUINO MEGA 5V board..
http://arduino.alhin.de/index.php?n=43

the MEGA Vcc is fluctuating a bit too..
while connected to external power supply,
i checked this via
http://hacking.majenko.co.uk/node/57

i must give the MCP3208 a Vref,
so i give the MEGA 5V as Vref for the MCP3208…
i have to await fluctuating measures, i guess..
and it was so…
for my purpose still too much fluctuating

so next step.. i use a voltage supply chip a  LM3940(low dropout), giving 3.3V from a 5V source, http://www.ti.com/product/lm3940,
these 3.3V will be the Vref for the ADC MCP3208
you have to use capacitors with the LM3940! otherwise you will not get the 3.3V output.
in datasheet 0.47mikroF and 33mikroF,  i used 4.7mikroF
with that  i get best possible stable values… till now
but after 10 good values, there comes always one value out of order/magnitude…
why? i dont know.. i will test an extra 5V powersupply for the adc..to check that
>> the error was in my SPI handling.. solved that, it works great

JPG
PDF

by the way
i would like to buy a Arduino shield, an ADC shield..
doing all the stuff, stabilizing Vref,
giving real world measures.. less offsets..
BUT there is nothong available in online-shops…
so i hope the people from
http://hacking.majenko.co.uk/node/27
will build the ADC shield

 

PS: alternativ power supply/converter
http://www.watterott.com/de/Breadboard-Spannungsversorgung-5V/33V
could used to get a stable Vref? LM317 could be interchanged with more expensive, better chip..

Python for programming Arduino

you can plug arduino via usb to a computer/laptop to use the computer/laptop for the main programm logic, using arduino only as sensor&actuator…

but powering an laptop all time..

hmm.. is there anything out there, using Python directly on the arduino?

you could use a cellphone/handy with symbian S60 and nokias DeveloperKit

arduino + Symbian S60
http://www.developer.nokia.com/Community/Wiki/Communicating_with_Arduino

or something more like this, python on a chip
arduino + py-on-a-chip
http://code.google.com/p/python-on-a-chip/
https://xcore.com/projects/python-chip

so i am waiting for a extra ArduinoPythonShield, in the plug and play way…
that would be great.. solving many starting problems with C/C++
having more fun, faster results..

Arduino Voltage Sensing

at first i tried a simple voltage devider, (Oreilly Arduino Cookbook page177)
3x1k + 1x1k, measureing above the 1k .. for measuring max 20Volts,

i connected my Mega2560 via usb… and the values where a little „fluctuating“..
i started calculating middle-values, 10%-influence of new value on old value,.. and so on..
BUT
today i gave a try on adding a external powersupply to the Mega2560.. and hey..
the analog reads went fine.. quite stable!
no need for me for „attopilot voltage current sensor“ anymore (maybe later ;o) )

without external power supply:
528 2.59 10.35
528 2.59 10.35
531 2.60 10.41
529 2.59 10.37
530 2.60 10.39
528 2.59 10.35
529 2.59 10.37
529 2.59 10.37
530 2.60 10.39
528 2.59 10.35

with external power supply:
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00
510 2.50 10.00

another fact, when fluctuating measurments occur, is
when i try to measure above a potentiometer 1kOhm(4Watt) with a 12V LED lamp in serie.
direct measures at the powersource, battery did not fluctuate.

 

 

 

model: 50V / 90A

http://www.sparkfun.com/products/9028 look for the datasheet there

Voltage Measurement Test

Pin Setup:
GND – GND
V – Analog 0

i want to measure Voltages between 11 and 15 Volts…
so i will test Analog Reads and proof at same time with an DigitalMeter.
adding the breakout parallel shows a voltage drop..?!

in datasheet is stated, that the voltage measurment has a 14,7kOhm resistor, my multimeter shows 15,75kOhm, maybe my multimeter isnt good enough.

the breakout is for 3.3V, with 5V you loose some precision.
http://arduino.cc/en/Reference/AnalogReference
so my arduino is a 5 V board, 10-bit resolution (0-1023)

 

measured analog values and an factor x

76 -> 5.74
77 -> 5.82
78 -> 5.89

tips:
http://electronics.stackexchange.com/questions/21963/arduino-mega-0-10v-analog-input

http://www.ladyada.net/learn/sensors/index.html

http://forums.adafruit.com/viewtopic.php?f=25&t=11597
  analogRead(5);
delay(10);
nTemp = analogRead(5) * 5000L / 1024L  / 10;

http://sites.google.com/site/measuringstuff/the-arduino 10-bit arduino explained

Python serial read for Arduino



# -*- encoding: utf-8 -*-
#

import sys
import time
import serial

print "ok"

# Parameter von Konsole entgegennehmen
#if len(sys.argv) != 2:
#   print "you have to pass the name of a serial port"
#   sys.exit(1)
#serial_port = sys.argv[1]

serial_port = "COM13"
arduino = serial.Serial(
   serial_port,
   9600,
   serial.EIGHTBITS,
   serial.PARITY_NONE,
   serial.STOPBITS_ONE)
   
time.sleep(2)

# continous read
line = arduino.readline()

while len(str(line))!=0:

      line = arduino.readline().rstrip()
      print line
      
#
###

Arduino DS3234 RTC output: YYYY-MM-DD hh:mm:ss

Original Code Snippet from sparkfun,
added YYYY-MM-DD hh:mm:ss output
i used Arduino MEGA-2560 via USB, power from USB,
important: i have to use SPI_MODE3 instead of SPI_MODE1 !!!
SPI_MODE1 delivered bullsh**

PinSetup
RTC – MEGA2560
————–
GND – GND
VCC – 3.3V
SQW – GND (squarewave signal output for interupters)
CLK – 52
MISO – 50
MOSI – 51
SS – 53


#include 
const int  cs=53; //chip select 

void setup() {
  Serial.begin(9600);
  RTC_init();
  //day(1-31), month(1-12), year(0-99), hour(0-23), minute(0-59), second(0-59)
  //SetTimeDate(27,4,12,16,5,0); // manuell Zeit setzen, kein 00 benutzen!
}

void loop() {
  Serial.println(ReadTimeDate());
  delay(1000);
}
//=====================================
int RTC_init(){ 
	  pinMode(cs,OUTPUT); // chip select
	  // start the SPI library:
	  SPI.begin();
	  SPI.setBitOrder(MSBFIRST); 
	  SPI.setDataMode(SPI_MODE3); // both mode 1 & 3 should work 
	  //set control register 
	  digitalWrite(cs, LOW);  
	  SPI.transfer(0x8E);
	  SPI.transfer(0x60); //60= disable Osciallator and Battery SQ wave @1hz, temp compensation, Alarms disabled
	  digitalWrite(cs, HIGH);
	  delay(10);
}
//=====================================
int SetTimeDate(int d, int mo, int y, int h, int mi, int s){ 
	int TimeDate [7]={s,mi,h,0,d,mo,y};
	for(int i=0; i<=6;i++){
		if(i==3)
			i++;
		int b= TimeDate[i]/10;
		int a= TimeDate[i]-b*10;
		if(i==2){
			if (b==2)
				b=B00000010;
			else if (b==1)
				b=B00000001;
		}	
		TimeDate[i]= a+(b<<4);
		  
		digitalWrite(cs, LOW);
		SPI.transfer(i+0x80); 
		SPI.transfer(TimeDate[i]);        
		digitalWrite(cs, HIGH);
  }
}
//=====================================
String ReadTimeDate(){
	String temp;
	int TimeDate [7]; //second,minute,hour,null,day,month,year		
	for(int i=0; i<=6;i++){
		if(i==3)
			i++;
		digitalWrite(cs, LOW);
		SPI.transfer(i+0x00); 
		unsigned int n = SPI.transfer(0x00);        
		digitalWrite(cs, HIGH);
		int a=n & B00001111;    
		if(i==2){	
			int b=(n & B00110000)>>4; //24 hour mode
			if(b==B00000010)
				b=20;        
			else if(b==B00000001)
				b=10;
			TimeDate[i]=a+b;
		}
		else if(i==4){
			int b=(n & B00110000)>>4;
			TimeDate[i]=a+b*10;
		}
		else if(i==5){
			int b=(n & B00010000)>>4;
			TimeDate[i]=a+b*10;
		}
		else if(i==6){
			int b=(n & B11110000)>>4;
			TimeDate[i]=a+b*10;
		}
		else{	
			int b=(n & B01110000)>>4;
			TimeDate[i]=a+b*10;	
			}
	}
        /* ORIG output
	temp.concat(TimeDate[4]); // tag
	temp.concat("/") ;
	temp.concat(TimeDate[5]); // monat
	temp.concat("/") ;
	temp.concat(TimeDate[6]); // jahr
	temp.concat("     ") ;
	temp.concat(TimeDate[2]); // stunde
	temp.concat(":") ;
	temp.concat(TimeDate[1]); // minute
	temp.concat(":") ;
	temp.concat(TimeDate[0]); // sekunde
        */
        
        /////
        // custom
        
        //temp.concat(" -- ");
        
        String DD = String( TimeDate[4] );
        if (DD.length()==1){ DD = "0"+DD; }
        
        String MM = String( TimeDate[5] );
        if (MM.length()==1){ MM = "0"+MM; }

        String YYYY = String( TimeDate[6] );
        if (YYYY.length()==1){ YYYY = "200"+YYYY; }
        if (YYYY.length()==2){ YYYY = "20"+YYYY;  } // ;o)
        if (YYYY.length()==3){ YYYY = "2"+YYYY;  }  // ;o)
        
        temp.concat( YYYY );
        temp.concat( "-" );
        temp.concat( MM );
        temp.concat( "-" );
        temp.concat( DD );
        
        
        String hh = String( TimeDate[2] );
        if (hh.length()==1){ hh = "0"+hh; }
        
        String mm = String( TimeDate[1] );
        if (mm.length()==1){ mm = "0"+mm; }
        
        String ss = String( TimeDate[0] );
        if (ss.length()==1){ ss = "0"+ss; }
        
        temp.concat(" ");
        temp.concat( hh );
        temp.concat( ":" );
        temp.concat( mm );
        temp.concat( ":" );
        temp.concat( ss );
        //
        /////
  return(temp);
}

tinkerforge microcontroller easy

http://www.heise.de/hardware-hacks/artikel/Angetestet-TinkerForge-Elektronik-Baukasten-1500925.html

offensichtilich ein Arduino Wettbewerber,

http://www.tinkerforge.com/

Python API
http://www.tinkerforge.com/doc/Software/IPConnection_Python.html#ipcon-brick-python

zum Batterien Laden/Entladen (Bedini Experiments) bräuchte man:

https://shop.tinkerforge.com/bricks/master-brick.html 30,-Euro
https://shop.tinkerforge.com/voltage-bricklet.html 4,-Euro
https://shop.tinkerforge.com/bricklets/current12-bricklet.html 10,-Euro
https://shop.tinkerforge.com/bricklets/dual-relay-bricklet.html 13,-Euro