Show Posts
Pages: [1] 2 3 ... 50
1  Using Arduino / Programming Questions / Re: How can I sample readings from sensor? on: Today at 10:16:40 am
Yeah, you're calling the getFrequency  function immediately after you attach the interrupt.  Just for testing, you could throw a delay in there between those two calls to give the thing a little time to run and catch a few interrupts before you ask it to get the frequency.
2  Using Arduino / Programming Questions / Re: Making print function work with F() macro on: August 20, 2014, 02:45:02 pm
Is there a way I can directly use the __FlashStringHelper* type by overloading my function rather than rewriting my display driver code?

If not, I'll commence rewriting.

You can overload the function to take a __FlashStringHelper if you are just passing that string along to something like print that can take one. 
3  Using Arduino / Programming Questions / Re: How can I sample readings from sensor? on: August 19, 2014, 02:30:33 pm


Code:
void GetReading() {
  float sens = FreqReading();
  for (int i=0; i<2; i++) {          //loop once to get just one reading
    sens;
   X=hz; //Store the value hz from FreqReading() function
  }
 
  }

First off, that function FreqReading is declared to return void.  So you can't expect sens to get anything but void from it. 

But moreover, I'm wondering what you thing this bit does?

Code:
for (int i=0; i<2; i++) {          //loop once to get just one reading
    sens;
   X=hz; //Store the value hz from FreqReading() function
  }

The line:

Code:
sens;
is legal code, but it doesn't do anything.  There's no command there, just the name of a variable.

And the next line references hz, which lives in the FreqReading function.  It doesn't exist in this function.  That should be throwing you a "not defined in this scope" error.
4  Using Arduino / Programming Questions / Re: var assignment on: August 18, 2014, 03:36:02 pm
I don't know if this is the case or not, but it would be my next try.

I don't know that you can count on that pointer remaining valid.  The pointer is coming from that callback function but you don't know if the data being pointed to is left there after that function exits or not.  So storing that pointer in another variable you may be keeping the pointer just fine but the data may be gone before you try to use it. 

I think I would work under the assumption that the data being pointed to is going to disappear.  I would use strcpy to copy the iPod name or whatever into another (global) char array and then keep my pointer pointed to that instead.  So instead of just capturing the pointer, go ahead and copy the whole string.  That way you know for certain when you come back for it that it will still be there.
5  Using Arduino / Programming Questions / Re: Collapsible Sub-Routines on: August 18, 2014, 01:58:04 pm
Or you could just use NotePad++ as an external editor for your Arduino IDE. 
6  Using Arduino / Programming Questions / Re: Calculating Celsius using Datalogger on: August 18, 2014, 01:35:30 pm

Fahrenheit to Celsius can be done in "many ways", see - http://forum.arduino.cc/index.php?topic=139006.0 - for a discussion

But the OP said he currently had temp data in K which is even easier.


Code:
int tempInC = tempInK - 273;

I don't understand the problem I guess.  If you can get the answer in K, then you only have to subtract to get C.
7  Using Arduino / Programming Questions / Re: progmem confusion on: August 17, 2014, 06:30:05 pm
Code:

#include <avr/pgmspace.h>
char buffer[16];


void addToBuff(prog_char* disp){
  int a =10;
  char insideBuf[10];
  strcpy_P (insideBuf, disp);
  sprintf_P(buffer, PSTR("%d%s%n"), a, insideBuf);
}

void setup(){
  Serial.begin(19200);
}

void loop(){
 
  addToBuff(PSTR("Hello"));
 
  Serial.println(buffer);
 
  delay(1000);
 
}

This appears to do what I want.  I can't find any way to get sprintf or sprintf_P to take a variable that is in progmem, but I don't mind the temporary buffer and the call to strcpy_P. 

I think I  still might see what happens if I derive my class from print and use F instead of PSTR.  Would there be any advantage?  This is done, I guess that makes it easier by default. 
8  Using Arduino / Programming Questions / Re: calling pinMode in the constructor on: August 17, 2014, 05:46:50 pm
and in particular it should not be trying to initialize the LCD in the constructor, because the power may not yet have stabilised and the LCD may not be ready.

There is a 50ms delay hanging out in there and a comment that goes with it that claims that it is for just that reason. 

50ms is an arbitrary value. If the begin() call is removed from the constructor, then the user can choose how much delay (if any) to use before calling begin().

I agree 100%.  That's why I think the library I'm writing I will change so that begin calls init at the very beginning and init doesn't call begin.  Then nothing happens with that class other than variable assignments until I call the begin method.  Then it will run init and begin.  Once I am good and ready. 
9  Using Arduino / Programming Questions / Re: progmem confusion on: August 17, 2014, 05:44:42 pm
I may have solved my own problem here.  If I go and derive the display class that I'm having trouble passing these to so that it derives from print then all I have to do is write code to put characters in the buffer (the virtual write method) and the print class will know what to do with the rest. 
10  Using Arduino / General Electronics / Re: Understanding grounds on: August 17, 2014, 01:04:26 pm
The test to see if they are floating is to connect them together with a 1K resistor. If you still measure the same differance then they are not isolated and you should not connect them together.

So I'm getting that the moral o the story is, "It depends on what happens when you connect them". 
11  Using Arduino / Programming Questions / Re: progmem confusion on: August 17, 2014, 11:50:31 am
Well, to start with, you'd have to find a version of sprintf() that supported progmem strings. :-(  (I don't think that one exists.)

There actually is one...
http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga53ff61856759709eeceae10aaa10a0a3

(I highly recommend using the n-version (snprintf_P vs sprintf_P).)



That would let me use the F macro on my format string? 


What about the other constant string.  The one I'm passing around as a variable.  I don't mind pulling them out and copying them to SRAM in the original caller just for the time that they're needed so I can pass them around as regular char*, but I have a lot of strings here and they can't all be hanging out in the heap together while they're not being used.

I've passed things around using the F() macro before by having the called function take a __FlashStringHelper.  That works great if you're sending it out Serial or something that takes a __FlashStringHelper, but as far as I can tell I can't use that with sprintf. 
12  Using Arduino / Programming Questions / Re: calling pinMode in the constructor on: August 17, 2014, 11:37:18 am
and in particular it should not be trying to initialize the LCD in the constructor, because the power may not yet have stabilised and the LCD may not be ready.

There is a 50ms delay hanging out in there and a comment that goes with it that claims that it is for just that reason. 

I'm modifying that library right now to use a shift register to drive all the pins so I can use SPI with it.  I need my pins back.  I thought I would just have to modify the virtual parts.  But when I got to that part I started thinking I might be making much bigger modifications.  The project it is going in has to call an init() function for about 12 different classes in setup().  I can't imagine one more would be an issue. 
13  Using Arduino / Programming Questions / calling pinMode in the constructor on: August 17, 2014, 01:22:06 am
I know it is a no - no to call functions from the constructor that rely on init() having already run.  So things like pinMode and digitalWrite should be in a begin method somewhere. 

So I always thought that is exactly what happened with something like the stock LiquidCrystal library.  But no.  Upon closer inspection, the constructor calls the LiquidCrystal::init() function which calls pinMode all over the place and then calls begin(16,1).  SO if you have a 16 x 1 display, you wouldn't even have to call begin because the constructor calls it! 

How does that work?  Is just moving it out of the constructor proper and into a function called by the constructor enough to pass?
14  Using Arduino / Programming Questions / progmem confusion on: August 17, 2014, 12:06:08 am
OK, I'm lost.  How would I modify this code so that both the format string and the string "Hello" are in progmem.

Code:
char buffer[16];

void addToBuff(const char* disp){
  int a =10;
  sprintf(buffer, "%d%s%n", a, disp);
}

void setup(){
  Serial.begin(19200);
}

void loop(){
 
  addToBuff("Hello");
 
  Serial.println(buffer);
 
  delay(1000);
 
}
15  Using Arduino / Project Guidance / Re: Reading variables from serial on: August 15, 2014, 02:58:36 pm
The variable names don't exist anymore once the code compiles.  If you want to do that you're going to have to set up a series of if tests one for each variable name.  If all the variables are of the same type then you could keep the names in one array and pointers to the variables in another array.  When you recieve a string you search for it in the name array and then access the value from the value array with the same index.  I guess a third option would be to define a template class that has members for the name and value and member funtions to match names and stringify values to go out over the serial connection.

But really a chain of if else if statements is going to be the quickest easiest thing.
Pages: [1] 2 3 ... 50