Show Posts
Pages: [1] 2 3
1  Using Arduino / Motors, Mechanics, and Power / Re: solenoid valves control ( design check ) on: February 15, 2014, 10:44:29 pm
I am so often impressed by the imagination and ingenuity of the code found on this site, but appalled  by the inability of so many to  implement the most basic interface to the world on the other side of the pins. People are continually trying to build the most basic of circuitry without any real grasp of basic principles. Why? On the coding side the beginner uses a library to safely isolate himself from mysteries yet to be more fully understood. Makes sense. One discovers more and more until some considered experimenting can take place.  So why not do the same for the hardware. If you need to connect a solenoid  use a "DriveLoad" or "DriveSolenoid" (there can be a difference) circuit found in a section of this site. It will stop senseless waste of time and well intentioned but often plain wrong offers of help. I think such a concept a match to the Arduino spirit and that we would soon see a profusion of well designed hardware blocks of great diversity for the beginner to just use. To IanDelord:
 There are a great many configs that work adequately. PNP, NPN,PFET,NFET, etc, etc. if you've got a big parts bin its worth reading up before picking one. If you're a beginner going from scratch and you want power just go for MTP3055VL fets.(if you are older you'll smile at the numbering) Why? Cheap. 12A/60V makes it a great starter. Easy to drive from 5V  (or 3v with care)  So its overkill for some. So what. Remember for anything sellable you really do need to know what you're doing. The 10 ohm resistor between the arduino and the fet gate is good practice but will work without for YOU. There may come a time when you really do need it. 1N4004 diode is ok for YOU. Gets the job done mostly. Now here's where  you JUST DO IT. (at least till you know better)  All power supply's commons (i.e 0V) Together. Directly. Short wires. Fat wires. Arduino 0V common  here. Other input commons also here. You REALLY want all of the 0v to BE 0V all over, all the time, not just when you're looking. Makes sure your load supply is up to the task. Especially if you are deriving your 5V logic supply from it.(there are tricks) Use a pull down resistor form the gate to 0v if you are likely to disconnect the arduino pin. Just touch the unconnected gate with your finger to see why. Few K ohm to few hundred K ohms is ok. Just remember things usually  mostly work if you're in the ball park.
Where is the park? Use google to search for it. A lot. Remember this has all been done decades ago. Don't overthink till you need to. I could go on, but I am getting boring and so maybe someone else could now run with this theme.
2  Using Arduino / Displays / OLED display with WS0010 controller on: May 26, 2013, 02:07:05 am
I have a Winstar 1602 (2lines x 16 char WS0010 controller) OLED display that I can't even initialise. Have trawled through various data sheets and sites that have different or conflicting initialisation descriptions.
I've got to the sad point  that I would swoon to just have a flashing cursor!. Is there a kind soul out there who has the definitive initialising sequence including necessary delays.
I have it setup in 4 bit mode and am confident I'm addressing it correctly. (RS=0, R/W=0 ,4 bits data then 100uS E pulse)
Regards all.
3  Using Arduino / Programming Questions / Re: Unexpected Serial.available() behaviour on: July 21, 2012, 10:15:21 pm
I hope everyone is learning something. Maybe it could be expanded in a new section: "The Psychology (or pathology) of Programming".
beepee: it's not funny anymore. I am sure there are other forums more suited to hosting your ego. Your post was solved long ago.
I am sure everyone would love to here your final post: "I've solved it by myself. Thank you all for the help"
4  Using Arduino / Programming Questions / Re: SoftwareSerial interrupt conflict? on: April 19, 2012, 07:49:06 am
Thanks for replies.
Actually the 2mSec interrupt is used to drive steppers at 500 pps(fast) 10pps(normal run) and a synchronised 60 led array. All my routines in loop are run once every 2mSec for timer2
Just including soft serial.begin in setup() with no other calls to SoftSerial causes the 10pps motor to vary significantly.(to say nothing of what happens to the leds)
Here's the gist( very much redacted) of the code:

SoftwareSerial GPS_comms = SoftwareSerial(A0,A1); // RX, TX
//----------------------------------------- setup -------------------------------------------
void setup(){
[color=yellow]  //GPS_comms.begin(4800);[/color]

  attachInterrupt(0,mainsInterrupt,RISING); // interrupt on digital pin 2
  //setup timer2 control registers
  TCCR2A = B00000000;    //normal operation, free running count up
  TCCR2B = B00000110;    //divide by 256 for 62500Hz (16uSec)
  TIMSK2 = B00000010;    //interrupt on OCR2A compare
  OCR2A = 125;           // next interrupt after 2mSec

//-------------------------------------- timer 2 interrupt ------------------------------------
  doRoutinesFlag=1;      //trigger for main loop
  OCR2A =OCR2A+125;
  if(intCount < 5){
    intCount +=1;         // reset to zero by mains intrpt
  else if(intCount ==5){
    powerOnFlag=0;       // mains has fail so adjust power on flag
  else if(intCount == 4){
    OCR2A +=20;          // add small value to ensure external intrpt triggers the next main loop



//-------------------------------------- mainsInterrupt ---------------------------------------
void mainsInterrupt(){
  TCNT2=0;             // resync timer to mains interrupt
  OCR2A =125;          // set next timer intrpt to 2mSec
  intCount = 0;        // was previously normally 4 (or 5 for extended power outage)
  doRoutinesFlag=1;    // trigger for main loop
  powerOnFlag=1;       //mains is back so adjust power on flag
//-------------------------------------- updateTime -----------------------------------------

//-------------------------------------- packBCD --------------------------------------------

//----------------------------------------sendByte --------------------------------------------

//-------------------------------------- read DS1302 -----------------------------------------

//-------------------------------------- writeHC595 ------------------------------------------

//------------------------------------- read keyboard ----------------------------------------

//--------------------------------- advance TargetCounters ----------------------------------------

//------------------------------------- moveMinuteHand ---------------------------------------

//------------------------------------- moveHourHand ---------------------------------------

//-------------------------------------- homeSwitchM -----------------------------------------

//-------------------------------------- homeSwitchH -----------------------------------------

//========================================= main loop =================================
void loop(){
  byte temp3;
  if( doRoutinesFlag==1){      // everything following done one time only



//------------ flash digit -------------

HERE is test GPS code to extract time. Works fine as stand alone.
  char keyPhrase[7]="$GPRMC";

void GPS_read(){
  if(flag==0){                // don't read while processing in case serial data changes


    if(tempK != -1){


      if (tempK==13){

    for(byte a=1;a<7;a++){

      hour[2]=0;        //string end character needed for the atoi function



      z=(z+10)%24;   //UTC +10hours for Victoria

      Serial.print(" : ");


      Serial.print(" : ");




5  Using Arduino / Programming Questions / SoftwareSerial interrupt conflict? on: April 19, 2012, 03:23:18 am
Hello Gurus,
I have a timer2 interrupt of 2mSec driving my entire clock motion control program (multiple stepper motors and multi LED display). The whole thing is synched to 50Hz mains for long term accuracy with DS 1302 chip during power out. Everything works just fine. But when I include SoftwareSerial in order to add A GPS module a problem arises.
Just adding the  .begin creates  unwanted interaction with the timer interrupt. I presume SoftwareSerial involves the use of other interrupts. Is there a way around this problem?
Theres no point posting code just yet. A few suggestions would be appreciated.  (IDE 1.0)
6  Using Arduino / Programming Questions / Disabling debugging prints on: April 24, 2011, 02:17:44 am
Hi all,
could anyone describe or demonstrate a good (easy?)way to disable a myriad of Serial.print's used for debugging when no longer needed. ie rather than removing them or marking them as comments.
I suspect a rather simple use of a macro and this would a most useful little tool.
7  Using Arduino / Programming Questions / Re: Convert Dec to BCD on: April 04, 2011, 05:50:30 pm
Not sure I understand the question. Do you mean your decimal interpretation of a value in a register? ie does "15" =0x0F?  isn't the example "27" stored internally as  0x1B? if so then what you want is Binary to BCD. Here is my take on using the ADD3 algorithm for converting binary to BCD. I only needed two BCD digits but it can be easily expanded.
//-------------- binary to BCD using add3 algorithm -----------
byte binaryToBcd(byte binSource){
  byte bcdResult=0;

  byte tempA=0;
  byte tempB=0;
  byte tempC=0;

  for (int y=0;y<8;y++){
    tempC=binSource & B10000000;
      bcdResult=bcdResult | B00000001;

    if (y<7){                             //don't check or do add 3 on last shift
      tempA=bcdResult & B00001111;        //check lo nibble
      if (tempA >= 5) { 

      tempB=tempB>>4;                     // check hi nibble
      if(tempB>=5) {

      tempA=bcdResult & B00001111;
      bcdResult= tempB | tempA ;          // reassemble nibbles
  return   bcdResult;
8  Using Arduino / Programming Questions / Re: Serial.print and ram usage. on: March 13, 2011, 12:41:41 am
Succinct and to the point.  Now today is a better day.
Thank you.
9  Using Arduino / Programming Questions / Re: Serial.print and ram usage. on: March 12, 2011, 09:53:44 pm
What I meant was, does something like Serial.print("hello"); use up any RAM
10  Using Arduino / Programming Questions / Serial.print and ram usage. on: March 12, 2011, 09:48:42 pm
I would like to hear any comments on why or if  Serial.prints use system RAM. I had no idea this could happen.
Aren't they stored in PROGMEM along with the rest of the hex code?
I am using lots of prints for debugging. Could this become a problem. If so is there any way to check?
11  Using Arduino / Motors, Mechanics, and Power / Re: 5 volt power supply design on: March 11, 2011, 09:58:36 pm
Here's the RECOM site. I have been buying from RS Components.
12  Using Arduino / Motors, Mechanics, and Power / Re: 5 volt power supply design on: March 11, 2011, 05:46:10 am
Check out  78B05  switcher from RECOM readily available from  various sources. Use just like a 7805. Same pin outs. 1 amp max out. No heatsink needed.
Been using these for some time. Really make your power supply problems go away!
Other voltages are available.
13  Forum 2005-2010 (read only) / Troubleshooting / Auto formatting needs fixing? on: March 03, 2010, 06:27:54 pm
Truly strange results when exceeding 80? chars per line. Will compile ok but generates error on autoformat.
Error too many parenthesis even though code was commented out. Actually cutting the comments out fixed it
Also strange wrap round effects.
Many hours of frustration before I twigged. hope no one else gets caught out. I put function names on the right
so they are easier to find in a long sketch.

.....going to mow the lawn for a while....
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: ISR behavior questions on: January 11, 2011, 08:59:36 pm
I know every one talks about keeping code in interrupt routines short, but it is possible and often practical to put ALL your code in interrupts.
To keep hardware and pin count cost down, my last few projects have used direct multiplexed led displays and push buttons for the user interface.
This necessarily means an interrupt driven system. With a period of 2mSec or so you have a nice stable display up to eight digits and nice simple de-bouncing of lots of switches. These instructions occupy only a tiny part of the available time period and one can pack a lot of code in the remaining time available.
You can also suspend your routine safely before an interrupt is due and continue the  routine in subsequent interrupt period safe in the knowledge that it won't be interrupted at an unknown point; or you can run any amount of less critical stuff outside the interrupt code. ie when the interrupt code is finished and the system is awaiting the next interrupt. Of course then you cant predict where your code will be when the int takes place.

As a relative amateur, I have asked a few questions of the forum and have learnt much from this very valuable resource. I hope someone may take advantage from this point of view.
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 18, 2010, 02:14:23 am
Here is my take on this.
16MHz clock to 16Khz means dividing by 1000.
Pick timer divider of 8. This means we need a further divider of 125.
I just add 125 to OCR2A every time an interrupt occurs.  
Works fine.
Simple routine flashes led at 8.000KHz to show it works

Note to CB: I'm still thinking about 124 but see for yourselves it definitely needs to be 125 in this setup


/*                       SIMPLE INTERRURP AT 16KHZ

 Platform: Arduino pro Mini 16MHz
 IDE: Arduino 0021
 V0.1  Nov 18 2010   Set up timer2 interrupt at 625nSec (16.000Khz)
#include <EEPROM.h>
volatile int flashCounter;
volatile boolean doRoutinesFlag=0;
boolean ledState=1;
#define testLed 13

//------------------------------------ setup ------------------------------------------------
void setup(){
  //set up timer 2 control registers here
  OCR2A = 124;              //initialise compare register for first interrupt
  TCCR2A = B00000000;       //select Normal Mode,freerunning counter, no connection to hardware pins
  TCCR2B = B00000010;       //normal, prescaler equals clock/8. With 16Mhz clock this gives an  2MHz clock to the TCNT2
  TIMSK2 = B00000010;       //generate interrupt on output compare match A
// --------------------------------- timer interrupt --------------------------------------

  OCR2A +=125;         //this generate an interrupt every .

  PORTB=PORTB | B00010000;   // turn on pin 12 every interrupt
  PORTB=PORTB &!B00010000;   // turn it off. It's enough width to see on CRO and frequency counter


// --------------- end timer interrupt ---------------

void loop(){

void flashLed() {    // just flash led at 8.000Khz
  ledState= !ledState;

    PORTB=PORTB | B00100000;
    PORTB=PORTB &!B00100000;


Pages: [1] 2 3