Show Posts
Pages: 1 2 3 [4] 5 6 ... 20
46  Using Arduino / Programming Questions / Updating data displayed only if it changes? on: June 30, 2013, 10:24:32 am
I've always had this question in my mind.  When sending out data to be displayed on an LCD display (or in my case an OLED display) I have always wondered if there is anything wrong with hammering the registers repeatedly with the same data over and over again.  Example:

Code:
void loop
{
  if(digitalRead(button))
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Not Pressed");
    display.display();
  }
  else
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Pressed");
    display.display();
  }
}

I hate that I am sending the same thing to the display over and over again when really I just need to send it once when the button is pressed and once when the button is released.  Because of this I end up doing something that feels convoluted like:

Code:
boolean last_button_position = false;
void loop
{
  if(digitalRead(button) && !last_button_position)
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Not Pressed");
    display.display();
    last_button_position = true;
  }
 
  if(!digitalRead(button) && last_button_position)
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Pressed");
    display.display();
    last_button_position = false;
  }
}

Now given my propensity to always find the absolute worst way to do something programmatically, I can only assume that this is possibly the worst way to do this.  What do you guys do to avoid constantly sending the same data to be displayed over and over again?

47  Using Arduino / Programming Questions / Re: How do i implement button state of change in this sketch on: June 30, 2013, 09:15:59 am
Just spitballing here, but would something like this work for you?  I haven't tested it but it should toggle On_Off with each button press and release.  Obviously bounce would be an issue but there are plenty of debounce examples out there.  I guess you could also have a missed press if you release at the exact moment after it tests for buttonPress and last_button_press and before it updates last_button_press with the buttonPress value.  I like to use interrupts for this type of thing but I know a lot of people shy away from that.

Code:
boolean On_Off = true;
boolean buttonState = true;
boolean last_button_state = true;

//check to see if the button was pressed and released
//it will detect the change from low to high when the
//button is released
buttonState = digitalRead(buttonPin);
if(buttonState == true && last_button_state == false) On_Off = !On_Off;
last_button_state = buttonState;

//and then test On_Off to decide whether to run your code of not
if(On_Off)
{
  //do all of your stuff here
}
48  Using Arduino / Project Guidance / Re: I'm out of memory? Is the next thing up the Mega644P? on: June 30, 2013, 08:24:54 am
Thanks to both of you!  Is the Arduino IDE support for the 1284 the same as for the 644?

WildBill, the code is fairly convoluted (as stated before, I don't know what I am doing), but I have posted it up on Github (mainly as a back up for me in case my macbook craps out).  It would be great if you would care to work your way through it to see if there are any major savings to be had.  Memory wise I am fine until I add the SD library.  I know there are some trimmed down versions but it would still be close and I would just like a bigger pool to swim in so that I can add more features.

It is located here:

https://github.com/jerseyguy1996/Leslie_GPS_Breadboard
49  Using Arduino / Project Guidance / I'm out of memory? Is the next thing up the Mega644P? on: June 30, 2013, 07:21:12 am
Well I've come to the sad realization that my code is just too long for the Mega328.  I am positive that part of this is just that I don't code very efficiently (because I don't know what the heck I am doing) but going through all of my variables, even if I put some of the constant data (strings and such) in progmem I am still going to be constrained and it won't allow for any additional features on my program.  I'm thinking the Mega644P may be a good next step up since it appears that the good folks at Sanguino have added support for this uC in the arduino IDE.  It doubles the amount of flash and sram relative to the 328.  It also comes in a fairly reasonably sized package (I don't need something in a massive 100 pin package).  Any thoughts on using the 644P as a reasonable next step up from the 328?
50  Using Arduino / Programming Questions / Re: Attachinterrupt question on: June 27, 2013, 08:05:18 pm
Great link!  That helps a lot!
51  Using Arduino / Programming Questions / Re: Attachinterrupt question on: June 27, 2013, 06:27:50 am
Great explanations guys!  Thanks!  I wanted to use the timer interrupts on the Atmega but there may be 2 or 3 functions that could run on one timer interrupt, based on the current state of the machine.
52  Using Arduino / Programming Questions / Attachinterrupt question on: June 26, 2013, 08:03:38 pm
Reading the documentation in the library reference it seems that this is allowed:

Code:
attachInterrupt(0, myISR, LOW);

//do something here


detachInterrupt(0);
attachInterrupt(0, myOtherISR, LOW);

//do other stuff

How does this work exactly?  My understanding of interrupts on the Atmega is that the interrupt jumps to the corresponding interrupt vector which has the instruction to jump to the ISR.  I wasn't aware that the ISR specified at the interrupt vector could be changed during the running of the program.
53  Using Arduino / Project Guidance / Re: Sketch too big!!! First time this has happened to me. on: April 07, 2013, 06:01:58 pm
I'll give that a try....i use sprintf in a couple of places so maybe I can trim some fat there.
54  Using Arduino / Project Guidance / Re: SD card library - Why does pin 10 have to be configured as an output? on: April 07, 2013, 05:47:38 pm
Definitely! Thanks!
55  Using Arduino / Project Guidance / Sketch too big!!! First time this has happened to me. on: April 07, 2013, 01:50:36 pm
This little block of code:

Code:
//    if(recording && newReading)
//    {
//    if(strcmp(messageID, "GPGGA") == 0)
//      {
//        char filename[13];
//        sprintf(filename, "%s.txt", date);
//        if(!SD.exists(filename)) Serial.println("Making Directory");
//        File dataFile = SD.open(filename, FILE_WRITE);
//        
//        // if the file is available, write to it:
//        if (dataFile)
//        {
//          dataFile.print(latitude);
//          dataFile.print(",");
//          dataFile.print(longitude);
//          dataFile.print(",");
//          dataFile.println(satsUsed);
//          dataFile.close();
//        }  
//      }
//    }

takes my sketch from 27,444 bytes (just under the 28,672 byte limit for the leonardo) to over 33,000 bytes.  Is there a seriously trimmed down version of the SD library or perhaps the adafruit OLED display library that anyone knows about?
56  Using Arduino / Project Guidance / Re: Possible to initialize the return value of a function? on: April 07, 2013, 01:25:30 pm
That is perfect!  Thanks to the both of you!
57  Using Arduino / Project Guidance / Possible to initialize the return value of a function? on: April 07, 2013, 01:14:17 pm
If I have a function such as:

Code:
boolean test()
{
     return a==b;
}

is it possible to initialize the return value of test to "false" the same way that you can initialize a boolean variable to "false"?
58  Using Arduino / Project Guidance / Re: SD card library - Why does pin 10 have to be configured as an output? on: April 07, 2013, 01:06:12 pm
The documentation states that the library won't function properly if pin 10 isn't configured as an output, even if you aren't using it as the chipselect.  I haven't been able to find any explanation as to why it won't function correctly or if it is just specific features that won't function correctly.  Can someone explain what it is that won't work if you don't configure pin 10 as an output?  I've commented that line out in some of the example sketches and it seems to still work fine.  I am using a Leonardo with the sd card wired up to the spi pins and I'm using pin A4 as the chipselect.

It has to do with the internal SPI hardware inside the AVR chip, using that pin to configure itself to be in master or slave mode depending on the pin mode of that pin, output mode = master mode, input mode = slave mode. The AVR datasheet is the source of such gory details. If you were using a totally software drive SPI function then that would not be an issue, but you would not be able to obtain the high performance possible with the hardware SPI unit.

Lefty

Perfect explanation!  Thank you.  The shield that I made uses pin 10 for another function but I guess lucky for me that functionality uses the pin as an output also.  I guess I would have had problems if the other functionality used that pin as an input.
59  Using Arduino / Project Guidance / SD card library - Why does pin 10 have to be configured as an output? on: April 07, 2013, 12:30:28 pm
The documentation states that the library won't function properly if pin 10 isn't configured as an output, even if you aren't using it as the chipselect.  I haven't been able to find any explanation as to why it won't function correctly or if it is just specific features that won't function correctly.  Can someone explain what it is that won't work if you don't configure pin 10 as an output?  I've commented that line out in some of the example sketches and it seems to still work fine.  I am using a Leonardo with the sd card wired up to the spi pins and I'm using pin A4 as the chipselect.
60  Using Arduino / Programming Questions / Arduino IDE and writing libraries on: March 30, 2013, 07:33:32 am
I have read through various tutorials on writing Arduino libraries, and they are great for teaching the syntax and structure of a library, but they never get into the real basics of things such as how to let the Arduino IDE know that you are writing a library so that it will save a file with a .h or .cpp extension instead of the .ino extension.  Is it just up to the user to rename the saved file with a .h or .cpp extension?
Pages: 1 2 3 [4] 5 6 ... 20