Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Development / Re: Contributing libraries on: March 15, 2009, 08:45:24 am
Absolutely typical... I wrote that post, then decided to try again... and of course, it works! Guess I must have had a loose connection somewhere...

Thanks for the library! Keep up the good work smiley-grin

*EDIT*

Actually there is a problem.

I can use the analogs (both of them) and get sane results. I can then map these values to 0-180 degrees for use with a servo. However, if I try to write the servo inside the loop() function, everything falls apart.

If I try to turn on the analog it flashes briefly on, then turns off (the red light, that is). Even without the servo, the controller starts up in digital mode (despite being set up to start in analog mode), but I can press the analog button and put it into analog mode.

So it seems the servo write is messing things up - any ideas why? Something to do with timers or some such?

Code is below:

Code:

#include <math.h>
#include <GPSXClass.h>
#include <Servo.h>
#include <WProgram.h>

Servo s1;

void setup()
{
  Serial.begin(9600);
  s1.attach(9);
  s1.write(90);
  
 PSX.mode(PSX_PAD1, MODE_ANALOG, MODE_LOCK);
  
  // Poll current state once.
  PSX.updateState(PSX_PAD1);
}

void loop()
{
  PSX.updateState(PSX_PAD1);

  // THIS WORKS
  byte b = ANALOG_LEFT_Y(PSX_PAD1);
  
  // THIS WORKS TOO
  b = map(b, 0, 255, 0, 178);
  
  // WITHOUT THIS, VALUES FOR b READ OVER SERIAL ARE FINE
  // WITH IT, NOTHING WORKS!
  s1.write(b);
  
  Serial.println(b, DEC);
  
}


*EDIT 2*

Needed a separate power supply for the servos... sorted now. And learned the lesson that servos don't like having their polarity reversed... oops. Ah well, won't be making that mistake again!

T
2  Forum 2005-2010 (read only) / Development / Re: Contributing libraries on: March 15, 2009, 08:41:25 am
I've been trying to use your library to use a PS2 controller to control some servos.

The buttons seem to work OK, but I can't get the analog sticks to function. There is no analog stick usage in the example sketch - could you put one up here, or msg me please?

I've been doing something along the lines of

byte b = ANALOG_RIGHT_X(PSX_PAD1);

But the value of b is always the maximum value (255). I'm quite sure the analog sticks on the controller work correctly. Has anyone else got this working?

For some reasons the analog light on the controller is not turned on either. If I press the analog button, the light flashes on briefly.

Any ideas?
3  Forum 2005-2010 (read only) / Interfacing / LCD4Bit did work,now LCD is very dim with 2 lines? on: December 15, 2008, 03:22:10 pm
Evening all.

I'm using the LCD4Bit library to interface with an LCD screen like this one.

I had it all working fine, with two lines being used on the LCD. I reverted to 1 line use of the LCD whilst running some test code, and now when I try to use the 2 line capabilities (that is, calling the LCD4Bit constructor with argument 2), the LCD is extremely dim. Now, it's pretty dim to begin with, and now it's barely visible. It is undetectable when plugged into my desktop, and just about visible when connected to my laptop. One line is just as bright as ever.

I'm wondering if some low level setting has been messed around with somewhere? I had a look through the library code but couldn't find any clues as to what the problem might be.

I've also tried with an external power source and the same phenomenon occurs. Does anyone have any suggestions as to why this might be happening? Perhaps the screen has been damaged... but with one line mode the top line is still bright, yet dim when 2 lines are used.

Typical that this happens the day before I need to do bit of a demo tomorrow! Hehe. Any help much appreciated.

Thom
4  Forum 2005-2010 (read only) / Interfacing / Re: Help with Hall Effect/RPM Please! on: December 04, 2008, 12:19:15 pm
Mike, thankyou, thankyou, thankyou! I've spent a ridiculous amount of time sweating over this, and the entire problem was due to my own silly assumptions and not paying attention to the data sheet!

I've rearranged the circuit to have the end leg as the control pin and hey presto, it worked immediately! I do have a bit of an issue with the fact it's a latched sensor, but that's easy to sort out with a bit of code or most likely a new sensor.

I've learned a valuable lesson here that I really should have been able to bring over from my coding experience - don't assume anything!

Should be able to get this thing working within the next couple of days now smiley-grin

Thanks a lot to everyone who contributed, it's been a brilliant help and saved me a lot of headache in the future, I think. No doubt I'll be posting some more queries soon.

Much obliged and indebted,

Thom
5  Forum 2005-2010 (read only) / Interfacing / Re: Help with Hall Effect/RPM Please! on: December 04, 2008, 10:37:04 am
Thanks for the quick reply.

So - I probably don't need a latched sensor (all of the ones I have are latched!) as I only want it to be triggered instantaneously as the magnet passes the sensor, right? But if it's a bipolar latched, and the magnet passes perpendicular to the sensor, will that quickly latch and unlatch the sensor?

If I've blown them, that's not too much of a problem (I ordered two of each, just in case - better safe than sorry smiley-grin ), I shall try again. What a stupid mistake for me to make, I just assumed that the 3-leg setup was similar to that of a potentiometer.

I'll go and take a proper look at the data sheet now and see if I can work out which way the thing is supposed to go in.

As for the wiring on the bread board, I'm pretty sure it's correct. The two bottom lines are connected horizontally, and the dots in the middle are connected vertically, no? So by connecting 5V/Gnd to the bottom two lines, you create a 'bus' to which you can connect the rest of the components? I think this is correct as I've had servos, LCD, distance sensor working correctly with this setup.

I've go and have another tinker with this now, and see what happens.

Many thanks again, it really is appreciated. I'm used to posting as a knowledgeable linux user so it's nice to be helped and not flamed as an electronics n00b, hehe.

Right, I'll get on with this and post back in a bit.

Cheers,

Thom
6  Forum 2005-2010 (read only) / Interfacing / Re: Help with Hall Effect/RPM Please! on: December 04, 2008, 10:09:41 am
OK, let's see if this works:



That's a little diagram of what I've done. I've also tried it with a resistor between the Hall effect sensor and the Arduino pin 2.

I'm pretty sure the interrupt code is correct as I've checked it with the ReadingRPM post on the Arduino playground.

A little note too - I'm not actually counting RPM as I've stated in the title, I just need to count the number of revolutions in total.

Cheers.

Thom
7  Forum 2005-2010 (read only) / Interfacing / Re: Help with Hall Effect/RPM Please! on: December 04, 2008, 05:08:37 am
Cheers for the replies people.

Scootabug: The ReadingRPM page was what I was referring to in the Arduino Playground. I can't really see how the fan/Hall Effect sensor is wired up in the picture, and part of my query was: do I need the resistor between the sensor and the arduino, or was that only for the PC fan (in the ReadingRPM configuration specifically). Also, where does the resistor go? I thought between the control wire and the Arduino? Sorry to sound like such a floundering fish, but I'm not sure where to swim next.

Grumpy_Mike: Damn, these sensors have polarity?! I looked at them and could not see any longer leg, or any sort of distinguishing characteristic for either side/face/edge of the sensor, so assumed they could be placed into the circuit in any orientation - is this incorrect? I guess I should be paying more attention to my datasheets. As I say, I'm a n00b to this (but willing to learn!). Is the 'limiting resistor' what I'm thinking of above?

I'll try to do a simple schematic. But basically the setup is Arduino_5V -> sensor side leg. (Other) side leg -> ground. Middle leg -> Arduino pin. It's essentially the same as the ReadingRPM wiring, but without the LED.

I'm also struggling here slightly with the difference between unipolar, bipolar, latched, latching sensors...

Thanks,

Thom


[edit]

What's the preferred way of posting pics here?

[/edit]
8  Forum 2005-2010 (read only) / Interfacing / Help with Hall Effect/RPM Please! on: December 03, 2008, 11:55:59 am
Hi everyone,

I'm trying to create an RPM measuring device, similar to those found in bike computers. Now, I'm doing this as a CS student and haven't had much luck finding help in getting the electronics working for this project.

I have 3 types of Hall Effect sensors that were available to me (I can order different types if anyone has suggestions).

Here are the 3 types I have:

180 Gauss Latched:
http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=1811457

180 Gauss 1 Polar Latching
http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=1811441

60 Gauss 2-Polar Latching
http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=1811463

Magnets:
http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=4346855#header


I am having difficulty wiring these with an Arduino. I'm not sure whether I need to add a resistor into the connection between the sensor and the Arduino, as in the ReadingRPM section of the Arduino Playground seems to suggest (but perhaps this is only for use with the PC fan setup).

I have tried all the sensors, wiring them with or without a resistor, with the ReadingRPM code. Am I using sensors that are too insensitive, or magnets that are not strong enough, or am I just completely getting the wrong end of the stick about how the sensor works?

My understanding is: magnetic field -> induce current in sensor -> pulse the control wire of the sensor (this is the middle wire, right?)

As you can no doubt see, I'm no electronics expert! But this seemed like something that should not be overcomplicated to set up, but has proved to be. This suggests to me I'm missing something that I probably wouldn't if I had a good electronics background.

Could someone please suggest some remedies for me? I cannot find any 'novice' instructions for wiring a Hall Effect sensor with an Arduino, and I don't have a bike computer sensor to hand to use instead.

If anyone has any suggestions at all regarding the sensors, the wiring, or the magnets, *please* let me know, I would be extremely appreciative. I'm sorry to ask for spoon feeding but my attempts to get this working have failed and are beginning to become frustrating!

Many thanks,

Thom
9  Forum 2005-2010 (read only) / Interfacing / Re: Ultrasonic Rangefinder (SRF05) Expected Results? on: November 26, 2008, 04:55:19 pm
Where did you use delay() instead of delayMicroseconds()? In the original code that you provided, or one of the ones I've put up since?

As for connections, I've disconnected and reconnected the components several time, and looked at the wiring diagram for the SRF05 every time I've reconnected, so I think I've got it right.

Will have another tinker now and report back if anything interesting happens.

Thanks.
10  Forum 2005-2010 (read only) / Interfacing / Re: Ultrasonic Rangefinder (SRF05) Expected Results? on: November 26, 2008, 06:11:32 am
Dang...

Well, assuming the software is OK it's most likely a cable/USB problem then, as it seems unlikely that I would have bought two faulty Arduinos and/or two faulty SRF05 units, doesn't it? I think I have only one USB cable of this type, I'll see if I can find another and try the combinations of board/sensor/cable on my desktop Linux machine, and my XP machine, and see what happens.

I found some code on a university site somewhere that seems to work... but I'm not sure why.

Code:
/* Ultrasound Sensor SRF05 v1
 *---------------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * http://www.xlab.se | http://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */

int ultraSoundSignalOut = 7; // Ultrasound signal pin
int ultraSoundSignalIn = 8; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

void setup() {
  beginSerial(9600);                  // Sets the baud rate to 9600
  pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
  pinMode(ultraSoundSignalOut, OUTPUT);            // Sets the digital pin as output
  pinMode(ultraSoundSignalIn, INPUT);            // Sets the digital pin as output
}

void loop() {
 timecount = 0;
 val = 0;

/* Send low-high-low pulse to activate the trigger pulse of the sensor
 * -------------------------------------------------------------------
 */

digitalWrite(ultraSoundSignalOut, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignalOut, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignalOut, LOW); // Holdoff

/* Listening for echo pulse
 * -------------------------------------------------------------------
 */

val = digitalRead(ultraSoundSignalIn); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
  val = digitalRead(ultraSoundSignalIn);
}

while(val == HIGH) { // Loop until pin reads a high value
  val = digitalRead(ultraSoundSignalIn);
  timecount = timecount +1;            // Count echo pulse time
}

/* Writing out values to the serial port
 * -------------------------------------------------------------------
 */

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

serialWrite('A'); // Example identifier for the sensor
printInteger(ultrasoundValue);
serialWrite(10);
serialWrite(13);

/* Lite up LED if any value is passed by the echo pulse
 * -------------------------------------------------------------------
 */

if(timecount > 0){
  digitalWrite(ledPin, HIGH);
}

/* Delay of program
 * -------------------------------------------------------------------
 */

delay(100);
}


This seems to increment the timecount for every iteration of the while loop where the pin is high - but how does this compute the distance? Does the while loop read the pin at a set interval, and then calculate the distance? This gives me seemingly accurate results but is different to any other way of using the SRF05 that I've seen.


Cheers,
Thom
11  Forum 2005-2010 (read only) / Interfacing / Re: Ultrasonic Rangefinder (SRF05) Expected Results? on: November 25, 2008, 08:35:10 am
I'm pretty sure the timing readings from the SRF05 are accurate - they're consistent when an object is placed at a fixed distance away.

The problem is the conversion. If I do (pulsetime/10000)/58 I get correct results for dist > 100cm but inaccurate below.

So, for (actual dist) = 200cm, the result will be 200cm, but the result for (actual dist) = 20cm will also be 200cm. Could it be something to do with the pulseIn method returning a value in mS rather than uS? I could hack something together that divides by 10000 for some range of pulse times, and by 100000 some other ranges, to make the numbers fit. But this seems like I'm just putting a plaster on things; curing rather than preventing.

Am I missing something obvious here? It feels like it...
12  Forum 2005-2010 (read only) / Interfacing / Re: Ultrasonic Rangefinder (SRF05) Expected Results? on: November 25, 2008, 07:52:28 am
Thanks for that - I tried changing the value for the delay, but sadly it didn't help. This seems to be an unusual problem - I've tried this new code with two Arduinos and two SRF05 units, and the same results are obtained.

I'm sure I've read pretty much everything I can find about this range finder on the net, and there don't seem to be any other suggestions to try.

Could it be something to do with my arduino software set up? I have only tried compiling and running this on my laptop, with arduino0011 and arduino0012 IDE, running on Ubuntu.

Cheers for the help so far guys, but are there any more (however long) shots?
13  Forum 2005-2010 (read only) / Interfacing / Re: Ultrasonic Rangefinder (SRF05) Expected Results? on: November 24, 2008, 11:33:27 am
Gah tried that, and I get even more erratic results! Hehe, I'm not sure what's going on here at all. I'll check this method on my other Arduino and the other SRF05 unit later on, for now here's the (new) complete code, after halving the ultrasound duration before dividing by 58.

Code:

int ultraSoundpin = 6;
char disp_string[80];
unsigned int ultrasoundDuration = 0;
unsigned int ultra_dist = 0;

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

void loop() {

  // switch pin to output
  pinMode(ultraSoundpin, OUTPUT);

  // send a low, wait 2 microseconds, send a high then wait 10 microseconds
  digitalWrite(ultraSoundpin, LOW);
  delayMicroseconds(2);
  digitalWrite(ultraSoundpin, HIGH);
  delayMicroseconds(10);
  digitalWrite(ultraSoundpin, LOW);

   // switch pin to input
  pinMode(ultraSoundpin, INPUT);

  // wait for a pulse to come in as high
  ultrasoundDuration = pulseIn(ultraSoundpin, HIGH);
  ultra_dist = (ultrasoundDuration/2);
  // output
  Serial.print(ultra_dist/58, DEC);
  Serial.print(" cm");
  //Serial.print(dist);
  //Serial.print(" cm");
  Serial.println();
  delay(2000);
}


I've tried this with unsigned ints and longs, and with a long for the duration and an int for the distance... just gives me random results from 7-500 odd....!

Thom
14  Forum 2005-2010 (read only) / Interfacing / Re: Ultrasonic Rangefinder (SRF05) Expected Results? on: November 19, 2008, 10:00:27 pm
Here's the full code just in case there's something I'm missing...

Code:


int ultraSoundpin = 6;
unsigned long ultrasoundDuration = 0;

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

void loop() {

  // switch pin to output
  pinMode(ultraSoundpin, OUTPUT);

  // send a low, wait 2 microseconds, send a high then wait 10 microseconds
  digitalWrite(ultraSoundpin, LOW);
  delayMicroseconds(2);
  digitalWrite(ultraSoundpin, HIGH);
  delayMicroseconds(10);
  digitalWrite(ultraSoundpin, LOW);

   // switch pin to input
  pinMode(ultraSoundpin, INPUT);

  // wait for a pulse to come in as high
  ultrasoundDuration = pulseIn(ultraSoundpin, HIGH);


  // output
  Serial.print(ultrasoundDuration/58, DEC);
  Serial.print(" cm");
  Serial.println();
  delay(2000);
}

15  Forum 2005-2010 (read only) / Interfacing / Re: Ultrasonic Rangefinder (SRF05) Expected Results? on: November 19, 2008, 09:57:55 pm
Hmmm yeah that's pretty much the code I've been using. If I try it with (ultrasoundDuration/58) I get this sort of result:

Code:

2032433 cm
2031355 cm
2030278 cm
2028122 cm
1988252 cm
2024890 cm
2031355 cm
2032433 cm
2022735 cm
812500 cm
813577 cm
2031355 cm
2031355 cm
2019502 cm
2020579 cm
2029200 cm
2030278 cm
845905 cm

Strange... I'm not sure what else to try here!
Pages: [1] 2