Show Posts
Pages: 1 2 [3] 4 5 6
31  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 07:45:16 am
Ok, this is maddening!

This morning, after posting the reply above I re-run the sketches without changing anything and they work!

One thing that I did not mention is that yesterday, after changing something here and there and re-verifying I was getting a bunch of random errors that did not make much sense, such as that I already declared variables that were not even in the sketch anymore.....

Next I will actually try to import my large bidimensional array with the same method and I may reach for help again, but thank you for taking the time to answer.

One thing: does Arduino work better in daytime?
Any problem with full moon?   smiley

32  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 07:37:32 am
How about posting the file? Or at least the first few lines of it.
Eventually, my goal is to import a bidimensional array of numbers, but right now, for testing purposes I am experimenting with the following:
The entirety of "mydata.hh" contains the following text:
Code:
"tizio", "caio", "sempronio"
The entirety of "numbers.hh" contains:
Code:
1,2,3,4
How big is this file, anyway? How many numbers are in it?
"mydata.hh" on disk is 30 bytes long.
"numbers.hh"on disk is 9 bytes long.
It should work, are you sure the baud speed is the same in the serial monitor window?
Yes I made sure they are the same.
With 1.0.1, the failure to find an include file doesn't even generate a warning.
The failure to find the include file would explain the behavior you are seeing.
I am using 1.0.1
If I don't put the whole path, the compilers gives me an error: "No such file or directory".

Thanks for your help.



33  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 12:14:37 am
In search for the way to import an array of numeric data from a separate file into my sketch, I found a post in a c++ forum that showcased this code:

Code:
static const char* data[] = {  // <--- new line
#include "mydata.hh"
};   // <--- don't forget semi-colon

I put in "mydata.hh" the following text:
"tizio", "caio", "sempronio"

and created the following sketch:

Code:
static const char* data[] = {  // <--- new line
#include "E:\Downloads\Devices\Arduino\arduino-1.0.1\data\mydata.hh"
};   // <--- don't forget semi-colon

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

void loop () {
  Serial.print (data[0]);
  Serial.println();
 
}

It compiles flawlessly but the serial monitor shows nothing (should show "tizio")!

Then I tried this:

Code:
static const int data[] = {  // <--- new line changed char* to int
#include "E:\Downloads\Devices\Arduino\arduino-1.0.1\data\numbers.hh"
};   // <--- don't forget semi-colon

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

void loop () {
  Serial.print (data[0]);
  Serial.println();
 
}

with numbers.hh containing:
1,2,3,4

It also compiles flawlessly but the serial monitor shows nothing (in other attempt it showed numbers totally unrelated to the content of the file)!

I feel I am very close on learning how to import numeric data from an external file but I am unable to walk the final mile.

BTW, Arduino reference says that using pointers is very complicate and I probably don't need them anyways  smiley-sad

Any help is appreciated

TIA
34  Using Arduino / Sensors / Re: Can I connect capacitive touch sensors to Pin 0 or 1? on: November 19, 2012, 06:38:54 pm
Got it. Leave 13 for LED smiley
35  Using Arduino / Sensors / Re: Can I connect capacitive touch sensors to Pin 0 or 1? on: November 19, 2012, 11:44:29 am
Thank!

Another quick question:

The refernce says it's better not to use Pin 13 for input with the internal pull up set.
Would the same caveat apply for the capacitve sensor?

code-wise is slighly easier to use 13 as well and put any LED on unused analog pins.
36  Using Arduino / Sensors / Re: Can I connect capacitive touch sensors to Pin 0 or 1? on: November 19, 2012, 07:14:45 am
But u can use digital pins 2 to 13 (=12 pins) and analog pins 0 to 5 (=6 pins numbered digital pins 14 to 19)...  smiley

However you can use the analogue pins as digital ones you know.

Waitaminute, I know how to read an analog pin and decide that if the result is, say, 600 or higher I consider it a HIGH.
But are you saying that I can simply decide that A0 is digital pin 14 and use the function:
Code:
PinStatus= readCapacitivePin (14) ;
from the code above, like I would do for any digital pin 2-13?

That would solve ALL my problems (or at least those related to this project. There is still the issue of the meaning of life and how to pay rent, but that's another story smiley )
 



37  Using Arduino / Sensors / Can I connect capacitive touch sensors to Pin 0 or 1? on: November 18, 2012, 10:46:08 pm
Hello All,
  In searching for the best touch sensor I was advised to look into a capacitive sensor:
http://arduino.cc/playground/Code/CapacitiveSensor

I was uncertain because in another post I read that it is too sensitive, reacting to proximity.
Well, for me it works marvelously, much better that even momentary push switches.

Problem is that I cannot use Pin 0 or 1, the function returns 0 no matter what (while it returns 1 for pin 2 to 13 when non touched and 4 when touched).

The reference: http://www.arduino.cc/en/Reference/PortManipulation  mentions that You should note, however, that pins 0 & 1 are used for serial communications for programming and debugging the Arduino, so changing these pins should usually be avoided unless needed for serial input or output functions. Be aware that this can interfere with program download or debugging.

I do need them as I have 14 touch sensors to read. I could live with 13 but I would still need port 0 or 1.

Is there a way around this limitation?

Thanks

This is the code I am using:

/* Uses the capacitive pin function
  to read capacitance on push buttons
  Connected to Pins 0 to 13
  Prints the values on the serial monitor.
*/


uint8_t PinStatus;
uint8_t cycles ;
byte i;

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

void loop ()
{
for (i=0;i<=13;i++) {
 PinStatus= readCapacitivePin (i) ;
 Serial.print (PinStatus) ;
 Serial.print(" ");
}
Serial.println();

}

// readCapacitivePin
//  Input: Arduino pin number
//  Output: A number, from 0 to 17 expressing
//  how much capacitance is on the pin
//  When you touch the pin, or whatever you have
//  attached to it, the number will get higher

//#include "pins_arduino.h" // Arduino pre-1.0 needs this

uint8_t readCapacitivePin(int pinToMeasure) {

  // Variables used to translate from Arduino to AVR pin naming
  volatile uint8_t* port;
  volatile uint8_t* ddr;
  volatile uint8_t* pin;

  // Here we translate the input pin number from
  //  Arduino pin number to the AVR PORT, PIN, DDR,
  //  and which bit of those registers we care about.
  byte bitmask;
  port = portOutputRegister(digitalPinToPort(pinToMeasure));
  ddr = portModeRegister(digitalPinToPort(pinToMeasure));
  bitmask = digitalPinToBitMask(pinToMeasure);
  pin = portInputRegister(digitalPinToPort(pinToMeasure));

  // Discharge the pin first by setting it low and output
  *port &= ~(bitmask);
  *ddr  |= bitmask;
  delay(1);

  // Make the pin an input with the internal pull-up on
  *ddr &= ~(bitmask);
  *port |= bitmask;

  // Now see how long the pin to get pulled up. This manual unrolling of the loop
  // decreases the number of hardware cycles between each read of the pin,
  // thus increasing sensitivity.

  uint8_t cycles = 17;
       if (*pin & bitmask) { cycles =  0;}
  else if (*pin & bitmask) { cycles =  1;}
  else if (*pin & bitmask) { cycles =  2;}
  else if (*pin & bitmask) { cycles =  3;}
  else if (*pin & bitmask) { cycles =  4;}
  else if (*pin & bitmask) { cycles =  5;}
  else if (*pin & bitmask) { cycles =  6;}
  else if (*pin & bitmask) { cycles =  7;}
  else if (*pin & bitmask) { cycles =  8;}
  else if (*pin & bitmask) { cycles =  9;}
  else if (*pin & bitmask) { cycles = 10;}
  else if (*pin & bitmask) { cycles = 11;}
  else if (*pin & bitmask) { cycles = 12;}
  else if (*pin & bitmask) { cycles = 13;}
  else if (*pin & bitmask) { cycles = 14;}
  else if (*pin & bitmask) { cycles = 15;}
  else if (*pin & bitmask) { cycles = 16;}

  // Discharge the pin again by setting it low and output
  //  It's important to leave the pins low if you want to
  //  be able to touch more than 1 sensor at a time - if
  //  the sensor is left pulled high, when you touch
  //  two sensors, your body will transfer the charge between
  //  sensors.
  *port &= ~(bitmask);
  *ddr  |= bitmask;

  return cycles;
}

 

38  Topics / Device Hacking / Re: Unpopulated UNO R3 board? on: November 18, 2012, 02:38:40 pm
Given the fact it's all open source hardware, couldn't you etch your own boards and follow one of the how to on the net to put together what you need?

http://www.instructables.com/id/How-to-make-your-own-Arduino-board/
39  Topics / Device Hacking / Re: Hacking a Mindflex to control a Robot on: November 18, 2012, 02:25:25 pm
Don't know if this is pertinent to your question, but this may help:
http://www.amazon.com/Make-Mind-Controlled-Arduino-Robot-Microcontrollers/dp/1449311547

40  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 17, 2012, 03:20:53 pm
Thanks AWOL and Nick,
  I am still baffled by the fact that in the declaration "1" means 1 total and in the assignment "1" means the second item: 0 - 1.
I keep on making this mistake and the IDE  keeps on reminding me about that (I'm glad the IDE didn't get tired of that yet).

Thanks also for the PROGMEM  tip and for the link! I can do it so long as the program does not need to modify it, correct?
Though it may not be necessary as an int array of 100 x 2 entries should occupy 2 x 100 x 2 = 400 bytes).
As the second numbers are not bigger than a byte I could create two monodimensional arrays, one int and one byte for a total of 100 * (2 + 1) = 300 bytes (plus some overhead, I assume).

Finally, can I put the code in a function at the end of the sketch and call it from setup(), maybe by stating somehow it's  a global array or, being it a variable assignment must it go before setup() (that would make the sketch neater) ?

Thanks
41  Development / Other Software Development / Re: Forth programming language? on: November 17, 2012, 09:54:42 am
So it might be worth another look...


You have my vote smiley

And also, during the (rather fruitless) research I've done prior to opening this topic, I came across pForth, which is an open source implementation aimed at portability. It has been ported to a ton of other systems, but surprisingly not to Arduino.
I wonder if for someone (like you) who has the right set of skills, this could be an easier/ more practical way to go:
http://www.softsynth.com/pforth/

Just a thought....


   
42  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 16, 2012, 09:24:15 pm
Thanks for all the answers !
I was (vaguely) thinking along the lines of dhenry and crossroads' solutions. I am going to research those
I was thinking maybe I can just #include  it or something.
Another thing i thought would be to create a library that does the data loading but that seems to me more trouble that it's worth, to keep the long list away from the program itself.

43  Using Arduino / Programming Questions / Importing a large lookup table on: November 16, 2012, 08:39:06 am
Hello,
   I need to setup a large (100 or so pairs of ints) lookup table to connect two set of numbers that are not mathematically related, i.e. One cannot be calculated from the other.
I am plannig to set up an array like this:

Code:
int table [100] [1] ;

And then fill it like this:

Code:
table [0] [0] = x0 ;
table [0] [1] = y0 ;
table [1] [0] = x1;
table [1] [1] = y1;
........................

I could easilly do it within the sketch but that would make the sketch heavy to read.
Is there a way to set up the table in a separate text file:

xo,yo
x1,y1
x2,y2
........

and then read or import it into the array?

That would have the additional advantage to be able to tweak the table without modifying verifying and re-uploading the sketch

TIA
44  Using Arduino / Programming Questions / Re: Elegant debouncing solution with software Schmitt trigger emulation on: November 15, 2012, 08:31:02 am
Cactusjack,
   Thank you for taking the time to show it to us.
This looks very useful indeed. The comments in the code are alifesaver.

I noticed that you use direct port access and a lot of bitwise operations and integer math to speed up execution.
I wonder if you could "translate" those instructions in common code (for lack of a better term) to help newbees like me understand their operations (not actually to be replaced as that would nullify the sped advantage)

Also, how would you use it in afuncion to detect button press and release (and act on them) after the algorithm has done its magic (i would't go so far as asking for a "led blink" example using your algorithm...though I think I just did...)?

You are using it wih three buttons, but i presume this can be used with any number of buttons.
Can the algorithm detect multiple simultaneus button presses, e.g. that button 1 & 3 have been pressesd and then button 1 (but not 3) released?


Finally, why do you need a while(true) statement in the loop() portion?

Sorry if  these questions look naive....


45  Development / Other Software Development / Re: Forth programming language? on: November 15, 2012, 07:28:35 am
Quote
So my question still stands: Anyone knows of a good Forth implementation for Arduino?

Any useful answer would be greatly appreciated.
So, you've googled and found nothing. Doesn't that tell you something?

Yes, it does. I guess i am afraid to face the sad reality.
 Call it denial if you wish but i was hoping that someone in this forum (which i find, for the most part, very useful) could give me hope.  smiley-cry

Oh well, i guess i'll ask this question again in 2 years.....
Pages: 1 2 [3] 4 5 6