Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Strange restarts when passing an array between functions using pointers on: June 11, 2014, 05:44:18 pm
This is a very peculiar one and I'm having trouble fully isolating the cause of the issue. It could be many things at this point, but after hours of trial and error I thing I've narrowed it down, although I don't really know why this is an issue.

Here's what I've got....  Adafruit CC3000 REST API passing params from the URL to custom functions to control RGB LEDs.

here's 2 example calls...

Set the LED to yellow:    http://###.###.###.###/setRGB?params=255,255,0
Fade the LED to Cyan over 5secs   http://###.###.###.###/fadeRGB?params=0,255,255,5000

The adafruit lib works like this...  To access a function defined in your sketch, you have to declare it first, and then call it from with a REST call. Note that all functions needs to take a String as the unique argument (for parameters to be passed to the function) and return an integer.

So I wrote a universal function to split a string of comma separated integer values into an array of long ints to use from within my different functions. Here it is:

Code:
void splitCommand(String command, long *vals, byte len) {
  int i = 0;
  int j = 0;
  int inChar;
  String inString;
 
 
  do {
    inChar = command[i];
    if (isDigit(inChar)) {
      inString += (char)inChar;
    } else if (inChar == 44) {
      vals[j] = inString.toInt();
      inString = "";
      j++;
    }
    i++;
  } while(inChar > 0 && i < 255 && j < len);
  if(j < len) vals[j] = inString.toInt();
}


So in my function for setRGB I use it like this...

Code:
int setRGB(String command) {
 
  long vals[3];
 
  splitCommand(command, vals, 3);
   
  red = vals[0];
  green = vals[1];
  blue = vals[2];

//do some stuff...

for now splitCommand() is used in 2 functions setRGB() and fadeRGB() but I will be writing lots more functions.  I have found if I only declare one of these functions in the REST api everything works.  If I declare both functions as REST calls I get strange results. Mostly random resets but also sometimes the functions just arn't available via the REST api.   If I just pick one of the 2 RGB functions and only declare that everything works great.  If I add another function it also works fine as long as it doesn't make use of the splitCommand() function.

Does anyone have any ideas, I'm totally open to a differnt solution for splitCommand()   I just need to turn the string of params into ints that can be accessed by different functions.

2  Using Arduino / Installation & Troubleshooting / Re: Sketch seems to upload but then AVRdude hangs and Arduino won't respond on: July 14, 2013, 07:21:47 am
Does the sketch have "!!!" anywhere in it?

Like:

Code:
Serial.print ("Danger!!!");

Quote
So I've been working on a sketch for a good few months now ... Unfortunately I don't have a copy of the sketch from when it worked

Time to learn about source control. Try downloading and installing "git".

Also make some backups from time to time.


Yes is does have a string with !!! and commenting this out solves all my problems!!!

Please explain lol

And yes I realise the values of source control,  this started off as a fun little project and grew into something that I now use and rely on. I will be taking much more care in future! Thanks for the advice, I should know better smiley-sad
3  Using Arduino / Installation & Troubleshooting / Sketch seems to upload but then AVRdude hangs and Arduino won't respond on: July 14, 2013, 07:12:06 am
So I've been working on a sketch for a good few months now and it is getting rather complex, although compiled it's only 18.4K.

It's been working fine in it's current iteration for ages and last night I made some very minor changes, since then it won't upload.

At first I thought maybe it was running out of RAM so I've commented out loads of strings, and a whopping 2000 element array of unsigned ints, so it's definitely using a lot less RAM than before.

But when I go to upload the sketch, it compiles fine, then I see the TxRx lights flashing away, then when they stop, the progress bar in the IDE stops moving and AVRDude just hangs.  The arduino sits there with the pin 13 LED flashing quickly, and an occasional flash n the Rx LED which I'm guessing is AVRdude trying to do something.

If I upload an example sketch everything works fine.  I've also tried my sketch on various MEGA2560s and tried uploading it form various computers.

It seems to be my sketch, but nothing has really changed from when it did work, to now when it doesn't.  Other than a few lines of mundane code.  Unfortunately I don't have a copy of the sketch from when it worked smiley-sad


Please help because this epic sketch controls my car and without it I simply can't drive it and I'm stuck lol

4  Using Arduino / Project Guidance / Re: Most accurate way to measure speed of a car on: February 26, 2013, 02:32:45 pm
Ah I see what you mean.
5  Using Arduino / Project Guidance / Re: Most accurate way to measure speed of a car on: February 26, 2013, 02:03:44 pm
Accelerometers:  I see what your saying, but I've already got an accelerometer based racetime, and some software for my phone that uses a combination of GPS + Acceleration, but neither are consistent or accurate enough.  The problem is I'm dealing with high speed and 100ths of a second.  For example the accelerometers become less accurate accurate unless your accelerating in a straight line on level ground. And 10Hz GPS isn't fast enough on it's own to be accurate.

Speedos: Forget the standard speedos in a car, I'm not using this.  I'm using a 9 tooth hall sensor on the rear diff at the moment and I will be changing to use a 48 tooth hall sensor on the front wheel. the main reason for this is that the car is RWD and spins the back wheels very readily, so as long as I stay in a straight line the front will be more accurate. At the moment 9 teeth is enough for me to read low speeds, but 48 teeth would be better. 1 pulse = 219mm and at 1mph (if my maths is correct) that's 0.48seconds per pulse, but this time quickly decreases, 8mph is 1 pulse per 60ms.

So it is a little slow at the start, but this will drop to around 1/5th the time when I swap to the 48 tooth ABS sensor. Although that also might make reading the pulse width much more difficult 1mph = 91ms, 32mph = 2.8ms, 128mph = 710us and so on.

6  Using Arduino / Project Guidance / Re: Most accurate way to measure speed of a car on: February 26, 2013, 10:11:14 am
Thanks for your detailed reply, it's confirmed a lot of what I was thinking.

I've actually got a separate counter for distance anyway, as you said this make much more sense.  Every pulse is exactly 1/9th of my tyre circumference. I started off with the pulse width speed measurement, then implemented the counter for distance and this is why I then went back to seed if the counting method could be used for speed as well.

I know what you mean about the rolling average, I've used this method before in sound sampling to get an "ambient sound level".  The only reason I went for the array is that I wanted mode, not average.  The main reasoning behind this was that I figured that the only errors in the data would really be if it some how missed a pulse, and say one of the values out of the last 10 would be double the rest.

When I was using a scope it did miss the odd pulse, but having tested the arduino it seems to be pretty reliable, and I might even just compare the last 2 pulse widths.

I guess if I was to build this to the nth degree I could include a GPS and even have an auto calibration that runs whenever a reliable GPS speed is captured and have the unit adjust itself. That would be pretty cool.

The main thing I'll be using this for though is displaying a heads-ups speed in mph, which doesn't need to be super accurate. Secondly when "race timer mode" is activated. It wait's untill you are stopped for 1 second, then when you start moving it starts timing.  It returns the 0-60mph time and the 1/4 mile time + speed accross the line. Then it stops the timing.  I'm also getting it to return the raw data via serial at this point.  Max 2000 samples, 1 per 10ms.

My next decision is what data to return,  speed or distance traveled.  Obviously one is a derivative of the other, but then that brings me back to which is more accurate,  speed based on pulse width, or distance based on pulse count.  I've not got this far yet and I'm sure once I have the raw data it should tell me.
7  Using Arduino / Project Guidance / Re: Most accurate way to measure speed of a car on: February 26, 2013, 09:18:44 am
No, unfortunately.
8  Using Arduino / Project Guidance / Most accurate way to measure speed of a car on: February 26, 2013, 08:58:21 am
At the moment I’m building a massive controller for my car (BMW M3 E36). It’s eventually going to control and read lots of devices on my car and operate via Bluetooth with my mobile phone.

I’ve started with the basics – a race timer.  This can read my speed and RPM and do some logging, timing and distance calcualtions.

I’ve got this working pretty well, I experimented with 2 different ways of measuring the speed, using pulses detected from my rear diff at a rate of 9 pulses per revolution.

I measured the timings, a pulse width of approx. 20ms was around 25mph. I then coded my idea and fine-tuned the readout with a GPS speedo.  Just out of interest I also coded an alternate idea I had which measured the revolutions and time and calculated the speed based on the circumference of my tyre. I’ll quickly describe each method below.


Method 1 – Reading the pulse width
------------

Set an interrupt for the speed sensor pin.
When this interrupt fires measure the pulse width by comparing the micros() from the last interrupt with the present micros()
If the pulse width is within sensible limits store this value in an array and move the pointer along 1
When the pointer reaches the end, jump back to the start

When you come to read the speed, I took the mode of the array which contained the last n samples.  (I can increase the size of the array, n, to give me more error tolerance but less instant readings)
I then do the following to turn the pulse width into a speed in mph.   speed = <a fixed number that I worked out> / pulseWidth;


Method 2 – Reading the revolutions per amount of time
-------------

Set an interrupt for the speed sensor pin.
When the interrupt fires add 1 to the revolutions variable.

When you read the speed you look at the time since the last reading and the number of revolutions counted, then reset the time and revolutions ready for the next reading.
Speed in mph = revolutions x circumference of tyre / time between readings



Now what I found was that using method 2, I only got very discrete speed readings.  Let’s say you sample the speed every 100ms, this means that at a certain speed you will either get 10 or 11 pulses every 100ms.  However the difference in mph between 10revs/100ms  and 11revs/100ms is quite a lot.  So my speedo would go up in 5mph steps for example.

So I guess I should stick with method 1, which I have only made accurate but comparing the output to a GPS speedo and making a number up that makes the calculation work. However I’m still worried that this method may be inaccurate. Because it comes down to measuring the pulse width in micro seconds, which at high speed is a very small % change in pulse width for a large change in speed. To make this worse I’m going to change from using my diff sensor, to using an ABS sensor, which will change from 9 pulses per revolution, to either 20 or 40 (I can’t remember which).

The end goal is, to as accurately as possible measure both speed and distance.  I then want to be able to time how long it takes to travel exactly ¼ mile to the nearest 100th second. That’s about 200 revolutions of my wheel, so potentially 18,000 samples or even more when I switch to the ABS sensor.

So what do you guys reckon the best way to do this is?
9  Using Arduino / Installation & Troubleshooting / Re: Programming a Mega2560 via BT on: February 13, 2013, 03:46:19 am
Does anyone have any suggestions, I don't know what else to try smiley-sad
10  Using Arduino / Installation & Troubleshooting / Re: Programming a Mega2560 via BT on: February 12, 2013, 03:14:22 am
DTR/CTS/RTS signals do not work with BT modules. You need to set BT module according to:
http://arduino.cc/forum/index.php?topic=132179.0
It works fine with my UNO..



As I said I've broken out the DTR pin from the BT module.  I can reprogram other Arduinos just fine, and I it's resetting the Mega 2560, but it's just not syncin up.
11  Using Arduino / Installation & Troubleshooting / Re: Programming a Mega2560 via BT on: February 12, 2013, 03:12:42 am
Are you able to load the same code to the 2560 via USB?

Yes if I swap the BT module for FTDI and leave everything else the same it works fine.
12  Using Arduino / Installation & Troubleshooting / Programming a Mega2560 via BT on: February 11, 2013, 04:37:55 pm
So I can program a Duemilanove just fine using an RN-42.  I've broken out the DTR pin and connected it via a cap.  Everything works fine.

I switched to a Mega 2560 and it just won't work.  First off I couldn't get it to auto reset, but though trial and error I fixed this by upping the cap to 10uF.

Not it auto resets just fine and appears to do something for a few seconds, but then just continues the old program and AVRdude hangs.

I've tried changing the BT device to 115.2kbps and 57.6kbps, neither work.

Any thoughts? I've run out of ideas.
13  Using Arduino / Project Guidance / Re: Long range wireless questions on: January 24, 2013, 05:34:00 pm
This?

http://proto-pic.co.uk/2km-long-range-rf-link-kits-w-encoder-and-decoder/
14  Using Arduino / Project Guidance / Re: How to NOT use an Arduino for simple wireless on: January 24, 2013, 04:01:45 pm
I've just done this exact thing, although I dont know if there's a better way or not.

I bought a 433mHz TX and RX for under £10.  Wired a 555 up to the Tx and used different capacitors connected in parallel via switches to alter the 555 freq.

Then I connected a pro mini up to the Rx and used a freq. counter lib that I found.  The received freq changed when different buttons were pressed on the Tx.

However because the Tx is constantly transmitting on/off, I found I'd inadvertently created an RF jammer, and with the Tx powered up I couldn't unlock any of the cars on my drive with the remote fobs!

I think something like this would of done the job a lot better, but it doesn't need to be as high powered...  http://proto-pic.co.uk/2km-long-range-rf-link-kits-w-encoder-and-decoder/
15  Using Arduino / Project Guidance / Re: Mega or Due? on: January 24, 2013, 03:23:00 pm
Yeah both Mega and Due  have pretty much the same I/O spec.

54 digital
12/14 pwms
4x serial

I'm just wondering what the Due has got going for it over the Mega
Pages: [1] 2 3