Show Posts
|
|
Pages: 1 2 [3] 4 5 ... 38
|
|
31
|
Using Arduino / Storage / Using the writeAnything utility without struct
|
on: February 06, 2013, 06:07:40 pm
|
This is currently what I have. I like to have more than one struct value so as to keep things organized in my mind: struct config_settings { //these are stored in EEPROM @ 50 int accel; //(516 orginally) Offset for the accelerometer when setting level int gyro; //(467 orginally) Offset for the gyro when setting level } offset;
struct config_steering { //these are stored in EEPROM @ 25 int center; //the value of the steering potentiometer in the center position } steering;
So then I can refer to them like: steering.center ...or offset.gyro
my question is: Since I only have one variable in the struct called steering, can I skip the struct, and just use a normal variable, like "steeringVal", and yet still use the writeAnything utility to save it to memory. I currently do this: EEPROM_writeAnything(25, steering); //save the steering settings to EEPROM @ 25
Could I skip the struct thing and just do this? int steeringVal = analogRead(steeringPin); EEPROM_writeAnything(25, steeringVal); //save the steering settings to EEPROM @ 25
|
|
|
|
|
33
|
Using Arduino / General Electronics / Re: looking for a louder buzzer
|
on: February 04, 2013, 01:08:17 pm
|
I would add a series resistor from D8 to the gate to protect against gate capacitance charge/discharge.
OK. Like a 330ohm or a 1K? I'm slowly learning about mosfets. I think the 1K would make it turn on slower? ...but in the case of a buzzer, it shouldn't matter.
|
|
|
|
|
37
|
Using Arduino / General Electronics / Re: looking for a louder buzzer
|
on: February 02, 2013, 10:32:57 pm
|
Thanks, Crossroads, My segway is powered by 24V, but I only have 5 volt coming onto my control board (supply from Sabertooth motor driver). I'm hoping to find one that is loud enough, but is PCB mountable, I like cutting out extra wires anytime I can. It will, however be in a plastic enclosure, at my feet, like this:  I wonder if this one would be loud enough to be heard? http://www.digikey.com/product-detail/en/MAS803Q/458-1257-ND/1957907 It probably would. It says continuous, does that mean I just have to turn it on, or do I have to give it PWM? It say 1.5 to 6 V. I'd give it 5 volts. I have some of these. http://www.digikey.com/product-detail/en/MMBT3904/MMBT3904FSCT-ND/458971 Would this work to power it? Thanks
|
|
|
|
|
40
|
Using Arduino / Sensors / Re: Calculating if I'm within 10% of the center of a pot
|
on: February 02, 2013, 07:01:59 pm
|
Here's what I ended up with: boolean StraightAhead( void) { int lowest, range, middle; int limit_low, limit_high; lowest = min (steering.left, steering.right); //the lowest of the 2 range = abs (steering.left - steering.right); //the range from left to right middle = lowest + (range / 2); //the center steering value limit_low = middle - (range / 20); // 5% lower than center limit_high = middle + (range / 20); // 5% higher than center int curentVal = steeringVal(); if (curentVal > limit_low && curentVal < limit_high) return (true); else return (false); } What is the difference between these two lines? Are they the same? boolean StraightAhead( void) { boolean StraightAhead() {
|
|
|
|
|
41
|
Using Arduino / Sensors / Re: Calculating if I'm within 10% of the center of a pot
|
on: February 02, 2013, 08:54:14 am
|
Are the steering.left and steering.right the raw values from the analogRead() functions ? Or are they calculated values from 0 to 180 (the degrees for the pot) ? I assume they are the raw analogRead() values. Is steering.left always the lower value, or could steering.left be the lower value ? How do you use the 10%. Do you want the range to be from -5% to +5% around the center ? I see 3 problems: (1) Your center is not the range divided by two, but you have to add the steering.right or steering.left (whatever is the lowest value). (2) Ten percent is "0.1", you use ".01" which is 1%. (3) A value of "0.1" or ".01" is a floating point value, and you use integers to calculate it. That is not possible. I used many variable in the next example, to show what is going on. // example, not tested
boolean StraightAhead( void) { int lowest, range, middle; int steering, limit_low, limit_high; lowest = min (steering.left, steering.right); range = abs (steering.left - steering.right); middle = lowest + (range / 2); limit_low = middle - (range / 20); // 5% lower limit_high = middle + (range / 20); // 5% higher steering = steeringVal(); if (steering > limit_low && steering < limit_high) return (true); else return (false); }
Thanks, yes, I see all 3 problems, and your were correct. steeringVal(), steering.left, and steering.right are all raw analog readings, though they typical range from 500-600 min/max, not 0-1024. So I think what you've come up with looks like it will work. I'll make a serial monitor debug loop and check it out. Thanks.
|
|
|
|
|
42
|
Using Arduino / Sensors / Calculating if I'm within 10% of the center of a pot
|
on: February 02, 2013, 01:16:06 am
|
This one's got me a bit stumped. On power up, I want my bot to wait until the steering mechanism is within 10% of 'neutral' Here's some variables I've got assigned to the min/max readings of the steering POT steering.left steering.right steeringVal() is another function that returns the current reading of the POT I'd like to make a boolean that will return TRUE if the steering is within 10% of center, or FALSE is it's not This is as far as I got, but I'm not really sure about it... boolean StraightAhead() { //returns true if within 10% of center int steeringRange = abs(steering.left - steering.right); //the total range of the steering POT int steeringCenter = steeringRange / 2; //the neutral steering position int tenPercent = steeringRange * .01; //10% of the range, I think if (abs(steeringVal() - steeringCenter) < tenPercent) return true; else return false; }
|
|
|
|
|
43
|
Using Arduino / General Electronics / Re: Map() function for curve
|
on: January 29, 2013, 07:25:03 am
|
|
Thanks, Robbins! That's what I'm doing, too. Even made some crude out of bounds voltages to detect connection failure, so things don't go haywire on a broken wire! I should've post a little detail about what I was doing/needing for the benefit of other readers. I'll take a look at your code...
|
|
|
|
|
45
|
Using Arduino / General Electronics / Re: Map() function for curve
|
on: January 28, 2013, 01:27:30 pm
|
Ok, so if I've got variables to work with instead of numbers, it'd be like this? unsigned long reading = analogRead(inputPin); unsigned long SQneutral = NeutralVal * NeutralVal; unsigned long SQmax = MaxVal * MaxVal; reading = reading * reading; reading = reading / (reading / 799);
|
|
|
|
|