Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Variable Delay: the big problem on: April 22, 2013, 01:47:12 pm
Did you try declaring your delay as an 'unsigned long' type?
2  Using Arduino / Project Guidance / Re: Sketch crashing (?) and repeating setup() on: April 22, 2013, 06:34:40 am
Quote
Code:
  char pin[5];
Code:
for (i = 0; i <= 5; i++)
      pin = ' ';

BZZZT!

THANK YOU VERY MUCH !!! ... Problem solved.

2700 lines... one character wrong... very unforgiving.  Guess I must have been over writing something important !

3  Using Arduino / Project Guidance / Re: Sketch crashing (?) and repeating setup() on: April 22, 2013, 06:08:05 am
Ok I've cut down a version of the code which still fails.  I've also tracked it down to a single line that causes it to fail.. marked with XXXX.  If I comment this line out the program works... uncomment it and I get the behavior described.

I'll try post a schematic of the circuit.. but in a nut shell a 20x4 LCD 44870 controller, and a 4x4 matrix keypad.

Now attached...

Code:

// Include the LCD library
#include <LiquidCrystal.h>



// Define the pin that turns the LCD backlight on/off.
#define LCDBacklightPin 13

 

// Define the pins for the keypad connections.
int rowPin[4] = {9,10,11,12};  
int colPin[4] = {5,6,7,8};

// Definition of global variables used throughout the program.

int GBL_userID = 0;                 // Currently logged in user.

boolean GBL_backLightIsOn = true;   // Whether the backlight is on/off.

unsigned long GBL_timePrevious = 0; // Last time we checked this user's time.

int i = 0;

// Create a serial instance representing the LCD, used globally.
// SoftwareSerial LCD = SoftwareSerial(0, LCDPin);

// LiquidCrystal lcd(RS, EN, D4, D5, D6, D7)
 
// Initialize the library with the numbers of the LCD interface pins
LiquidCrystal myLCD (1, 2, 3, 4, A1, A0);

// One time setup & initialisation.

void setup()
{

//  Serial.begin(9600);
 

  // Initialise the pin used for the LCD backlight.
  pinMode(LCDBacklightPin, OUTPUT);

  // set up the LCD's number of columns and rows:
  myLCD.begin(20, 4);

  // Initialise the key pad.
  for (int i = 0; i <=3; i++)
    {
      pinMode(colPin[i], OUTPUT);
      digitalWrite(colPin[i], LOW);
      
      pinMode(rowPin[i], INPUT);
    }    

  lcdBacklight(true);

  lcdClear();
  lcdPosition(0,0);
  lcdWriteString("setup done");
  delay(1000);  
}



// Main program loop.

void loop()
{  
    lcdClear();
    lcdPosition(0,0);
    lcdWriteString("loop start");
    delay(1000);  
        
    // Prompt the user to log in.      
    T0_userLogin();
  
    lcdClear();
    lcdPosition(0,0);
    lcdWriteString("loop end");
    delay(1000);  
}

// The first time after powering up we force the Admin to log in.  This is to prevent someone disconnecting the power without being noticed.

// Routine to get a user from the login screen.  Will not return to caller until a user is found.

void T0_userLogin()
{
  char pin[5];

    // Display the login prompt
    
      lcdClear();  
      lcdPosition(0,0);
      lcdWriteString("input screen");

      delay(500);
    
  
    for (i = 0; i <= 5; i++)
      pin[i] = ' ';

    // Get the PIN number from the user.
    int result = getInput(2, 1, pin, 5, 5, true, 0, false);

//   char keyPressed = getKey(5000,false);

 
}



// Routine to get write a value to the LCD, and allow it to be edited via the keypad.

int getInput(int row, int col, char before[], int minChar, int maxChar, boolean hidden, int alpha, boolean CRReq)
{
   lcdCursor(true);  

    char keyPressed = getKey(5000, false);

    return 0;
}  

// Get a key from the keppad.
// If more than timeout milliseconds pass without a key being pressed then an error 'X' will be returned.

char getKey(int timeout, boolean switchBacklight)

{
    
//  return 'X';
  
  // Define the key values to be returned.
  char key [4][4] = {{'1', '2', '3', 'A'},
                 {'4', '5', '6', 'B'},
    {'7', '8', '9', 'C'},
            {'*', '0', '#', 'D'}};

  // Keep track of the start time.
  long startTime = millis();
  
  // Difference between the start time and the current time.
  long duration;  

    while (true)
    {

      // Check to ensure the timeout value has not been reached.  If it has we stop and return 'X'.
      duration =  millis() - startTime;
    
      if (duration > timeout)
      {
        if(switchBacklight)
          {
            GBL_backLightIsOn = false;
            lcdBacklight(false);
          }

        return 'X';
      }

      // Scan the keypad looking for a key press.
      for (int i = 0; i <=3; i++)
        {
            digitalWrite(colPin[i], HIGH);

   for (int j = 0; j <=3; j++)
   {
                          
                if (digitalRead(rowPin[j]) == HIGH)  // A key is being pressed.
                    {
                        unsigned long before = millis();
                        
                        while (digitalRead(rowPin[j]) == HIGH); // Wait until the key is released.
                        
                        delay(50);  
                        
                  if (!GBL_backLightIsOn)
                          {
                          GBL_backLightIsOn = true;  
                          lcdBacklight(true);
                          }
              
                        digitalWrite(colPin[i], LOW);
                        return key[j][i];  
                    }
   }
            digitalWrite(colPin[i], LOW);
        }
    }
}


// ------------------- LCD control routines ----------------------------------------------------------


// Routine to position the cursor within the display.

void lcdPosition(int row, int col)
{
  myLCD.setCursor(col, row);
}


// Routine to turn the cursor on/off. Replaced with debug code
void lcdCursor (boolean on)
{
  // The following line causes the sketch to fail.
  
  lcdWriteString(" fails");  // XXXX
}

// Routine to write something to the LCD.
void lcdWriteString(char string[])
{
  myLCD.write(string);
}


// Routine to write a single ASCII character.
void lcdWriteByte(byte string)
{
  char myChar = string;
  myLCD.write(myChar);
}


// Routine to clear the LCD screen.
void lcdClear()
{
  myLCD.clear();
}


// Routine to turn the LCD backlight on/off.
void lcdBacklight(boolean on)
{
 
  if (on)
  {
    GBL_backLightIsOn = true;
    digitalWrite(LCDBacklightPin, HIGH);
  }
  else
  {
    GBL_backLightIsOn = false;

    digitalWrite(LCDBacklightPin, LOW);
  }
}  










4  Using Arduino / Project Guidance / Re: Sketch crashing (?) and repeating setup() on: April 22, 2013, 05:28:12 am
If the Arduino is not reseting then is there another explanation of why the setup() routine gets executed repeatedly?

Thanks.
5  Using Arduino / Project Guidance / Sketch crashing (?) and repeating setup() on: April 22, 2013, 04:57:51 am
Hi

For some reason my Arduino sketch seems to be crashing and I've can't figure out what is going on.  My suspicion is some kind of overflow - the error seems to occur at the bottom of the loop() routine.  I'm reluctant to post the full code (it's around 2700 lines, and requires a number of hardware components... but can if someone thinks it will help).

In a nutshell with a simplistic view of the code...

Code:
void setup()
{
  // code

  // debug output to LCD "setup complete"
}

void loop()
{
  // debug output to LCD "loop start"

  // other code

  // debug output to LCD "loop end"
}


Output expected...

setup complete
loop start
loop end
loop start
loop end
...

What I actually get...

setup complete
loop start
loop end
setup complete
loop start
loop end
...

So for some reason is seems to crash at the bottom of the loop() routine and resets.

Anyone got any ideas what could cause this sort of behavior?

Appreciate any assistance.

 
6  Using Arduino / Displays / Re: Problem with HD44780 LCD - cursor movement on: August 30, 2012, 02:28:39 pm
Thanks Don... I'm a newbie so appreciate the info.  The link provides an excellent description of the display addressing.

I now see why the 'shift cursor' functions as it does. 

Does seem odd that that when writing characters to the display this seems to be compensated for.  ie. characters are written to the display as expected... lines 1-2-3-4.

Cheers
7  Using Arduino / Displays / Problem with HD44780 LCD - cursor movement on: August 30, 2012, 06:09:10 am
Hi all

I've been trying to use a 20x4 HD44780 LCD display as part of my Arduino project.

The HD44780 command set includes commands for moving the cursor left and right, however when using this I have noted some strange behavior.

On each line the cursor moves as expected, however when it gets to the end of the line it does not go to the next line as expected but follows the sequence Line1 -> Line3 -> Line2 -> Line4.

Anyone come across this issue before?

Thanks in anticipation.



Code snippet below...

Code:
#include <SoftwareSerial.h>

#define txPin 12

SoftwareSerial LCD = SoftwareSerial(0, txPin);

void setup()
{
  LCD.begin(9600);
  
  // Clear display
  LCD.write(0xFE);  
  LCD.write(0x01);
  delay(3);
  
  // This works as expected filling the screen with 'X's.  Line sequence 1-2-3-4
  for (int i = 1;i<=80;i++)
  {
    LCD.write("X");
    delay(100);
  }
  
  // This doesn't work as expected.  Line sequence 1-3-2-4.
  for(int i = 1;i <=80;i++)
  {
    LCD.write(0xFE);     // Command to follow.
    LCD.write(0x14);     // Move cursor to right.
    delay(100);
  }
}

void loop()
{
}
8  Topics / Device Hacking / Re: Arduino to switch HDMI on/off ??? on: August 30, 2012, 05:53:20 am
Thanks for all the ideas.. off to try some out.  Will let you know how I get on.
9  Topics / Device Hacking / Re: Arduino to switch HDMI on/off ??? on: August 26, 2012, 06:57:58 am
Another option I thought of was using a digital switch.. such as this ... http://www.ebay.com/itm/400312722729?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649#ht_1950wt_1095

I could use it to interrupt the data transmission in the cable (seems there are 3 separate data channels in HDMI).

Anyone have experience with this type of digital switch ?  I was looking for an 8 bit one but there don't seem to be any around in the DIP package style.
10  Topics / Device Hacking / Re: Arduino to switch HDMI on/off ??? on: August 24, 2012, 06:00:19 pm
Thanks for the replies guys.

Yep..definitely an opto isolator to trigger the circuit.

One thing I did notice about these switches was that they not only switch based on the button, but also if there is only one live input.  Presumably they sense the signal somehow.  Unfortunately this isn't desirable in my case... As this would bypass my Arduino logic.

I might still get one and crack it open... Could still be an option if I can disable the auto switching function.

Re the transistor option... I don't quite understand how this would work.  I can see that it provides a switch but don't quite see how I could use this to pass the signal down the cable. 


Thanks
11  Topics / Device Hacking / Re: Arduino to switch HDMI on/off ??? on: August 24, 2012, 03:20:01 pm
Thanks for the reply.

Do you think I could get away with doing this to just some of the wires within the cable?  I presume that some of them are more critical than others for sending the video signal?  Any ideas on the minimum number I would need to block to effectively turn off the signal?

Thanks.
12  Topics / Device Hacking / Arduino to switch HDMI on/off ??? on: August 23, 2012, 10:06:02 pm
Hi all

Looking for a little expertise from the forum gurus...

I would like to use an Arduino UNO to control whether an HDMI signal can be sent over a cable.  The UNO would sit between the HMDI source (PS3) and receiver (TV)... and depending on certain conditions will either allow the HMDI signal to pass through or not.

I know that HMDI cable contain a number of channels for various things over 19 separate wires.  Is there one of these that I could isolate that would have the desired result ?  I was antipcating some surgery to the cable.

Any ideas around a possible circuit that could be used to acheive this (i.e. UNO PIN high allows pass through, UNO PIN low blocks signal) ?

Thanks in advance for your help.

Pages: [1]