Show Posts
Pages: 1 2 3 [4] 5 6 ... 81
46  Using Arduino / Project Guidance / Re: sd card reader for PC on: March 19, 2014, 01:35:30 pm
Everyone here - or very close to everyone - does suff that is reinventing the wheel. Not to be more efficient or save money but "because". Same reason why people climb mountains. Applaus and kudos to all inqusitive and tinkering minds !

Now, I do not have an Leonardo myself, but if i remember it acts (or can act) as a keyboard or mouse, not as a disk drive. That may the real challenge.
47  Using Arduino / Project Guidance / Re: Servo Control For Robot Hand on: March 19, 2014, 01:30:04 pm
I think it is a nice answer too, but is there any difference?

Both the analogWrite PWM and the Servo.write() PWM are fixed frequency, and vary the width of the pulse. Both encode an "analog signal" in the digital wave. Both make their magic by using timers and interrups so the waves are generated in the background.

The difference is that the mark-space ratio for "ordinary" PWM varies bewteen 0 to 100% and for the servo between 5 to 10%; the frquency is 430Hz on the analogWrite  PWM and 50Hz on the Servo PWM.

The term PWM is correct for both,  but "common use" in the Arduino land is the PWM is the analogWrite type.

I look forward to corrections and enhancment to my knowledge (not sure about the analogWrite frequency) - honestly!  smiley
48  Using Arduino / Programming Questions / Re: Can't get stepper motor to work in a specific situation on: March 19, 2014, 12:46:52 pm
When button 5 is pressed, it writes digital pin 1 high, waits then writes it low. It records that it made that step (stepdis = stepdis +1)
then it checks to see if it has arrived in the desired position using the if statement. If the stepdis (steps traveled) = dis (desired steps to travel) then set pins 0 and 1 to LOW.
So what happens if I have not done any +/- 1 or +/- 10 on the buttons and then push #5? It will do a step (as the only condition for doing a step is that pushbutton 5 is down - as far as I saw) and then it will probably conclude that dis is no longer like stepdis and thus continue.... ahh... no...  now I see our common mistake. The outer if checks if button 5 has changed state. And if we keep button 5 depressed it will not have changed state and we will not enter the loop. Ie for each button 5 press the stepper will only move one step. (Apart from button bounce which may make it do an down/up 2 .. 5 times, each time moving one step. Depends on your button quality) So you ned an appropiate for loop and you need to set the direction pin before the step according to something like dis<stepdis.

How do I get pin 1 to toggle at a slower frequency, and what frequency would you recommend?
increase the delayMicroseconds(). If your circuitry has microstepping then 5K may work at 16th step, but if you do full steps then 1K would be fast. Depends on the mechanical load/motorsize. I would do delay(500) in my first version (ie 1Hz steps) to count each step

You do things like
const int switchPin1 = 6
so why not
const int StepDirPin = ...

And clean up the errenous comments. When/if you post a new version, do put the code in boxes like every other good person does. Please.
49  Using Arduino / Programming Questions / Re: Can't get stepper motor to work in a specific situation on: March 19, 2014, 10:52:24 am
(This is how you should include code use the #-button above the text edit box)
if (switchState5 == HIGH) {
      // move the cursor to the second line
          digitalWrite(1, HIGH);
          digitalWrite(1, LOW);
          stepdis = stepdis + 1;   
          if (stepdis == dis)
That code is missing something to decide if we are going + or -.
As long as button 5 is held down it will toggle pin 1 at 5 Khz - possibly too fast. Your test for stepdis==dis is after you HAVE made a step - wrong logic? You sure you have not mixed up direction and step in your pinout? that is usually the reason "it wont move" Unless you are really desperate short of pins do not use pin 0 or 1 as this is "in parallel" with the USB/serial interface. digital pin 14 is the same as the A0 pin, but in digital form. Lastly but not at least - the top comment in above snippet is wrong -presumably the stepper is not moving any cursor(s). Wrong comments can be really confusing.
50  Using Arduino / Programming Questions / Re: Little help here please on: March 19, 2014, 10:36:14 am
I wager that the servo example in the IDE gives you enough to go on.

Instead of digitalWrite(LED,HIGH) use MyServo.write(180), and MyServo.write(0) at the opposite. Copy and paste the appropiate #include and MyServo.attach() and you're done.
51  Using Arduino / General Electronics / Re: Need urgent help for my motor drive design. on: March 19, 2014, 10:28:57 am
wait to make sure your relay has settled to off, THEN switch your direction, wait for the relay to settle, then turn the motor back on.  Otherwise you might accidentally manage a short your power-supply if things don't switch consistently.
Sorry, that did not make sense to me. If the direction relay is a double pole double throw then no amount of turning relays on/off wil make a short (unless the relay is very cheap crap) Where you thinking of arcing or back EMF of the motor?'

Maybe the OP (ohandl) should tell us the power/voltage ofthe motor - it may not be significant.
52  Using Arduino / Programming Questions / Re: Programming Questions on: March 19, 2014, 07:24:54 am
You code VERY QUICKLY as the new program does quite close to the suggestions I made. smiley

It, too, is small enough to display inline, please do so using the [#] button. (new post or edit the above)

On a quick glance at the program it seems correct ... but what is it that does not work for you ?
53  Using Arduino / Programming Questions / Re: Stepper programming on: March 19, 2014, 07:04:19 am
It's the usual : "I could not be bothered to find the info via Google to start with, but the links given have so much text, is there not something simpler I can just cut-n-paste" - type discussion. I think. But the Original Poster may prove me wrong. Please.
54  Using Arduino / Programming Questions / Re: SD Read with break variable on: March 19, 2014, 07:00:32 am
Are you trying to read the file on your computer or in the Arduino?
55  Using Arduino / Programming Questions / Re: MODBUS protocol. on: March 19, 2014, 06:58:44 am works for me
56  Using Arduino / Programming Questions / Re: Programming Questions on: March 19, 2014, 06:57:10 am
(That program is so short so it can displayed inline -easier for folks to see)
int leds[] = {0,1,2,3,4};
int switchPin = 5;

void setup() {               
  for(int i=0;i<5;i++) {
      pinMode(leds[i], OUTPUT);   
  pinMode(switchPin, INPUT);

void loop() {
  int state = digitalRead(switchPin);
  while(state != 0) {
    for(int i = 0; i < 5; i++) {
      digitalWrite(leds[i], HIGH);
      int potValue = analogRead(A0);
      digitalWrite(leds[i], LOW);
    state = digitalRead(switchPin);
And that program turns on the LEDS and turns them off with a speed that is proptional to the pot value (between 0 and 1.023 seconds) Nothing wrong with that, but I suggest you do not use pins 0 and 1, as they are used for uploading and doing debugging Serial.prints. Nice use of array to abstract LED number from pin number. You're missing 2 LEDS (you said 7). Strictly speaking the test for the switch should be state=LOW or HIGH not 0 or 1.

I think you have enough understandig of the C/c++/arduino to do the coding, if you more detailed describe the steps:
1: wait until switchpin reads depressed. Store the A0 value somewhere. Turn on LED4.
2: another while loop that now subtracts the new A0 value from the stored one, if negative, multiply by 3 then divide by the stored a0 value, take abs() and now you should have a number between 0 and 3 that is how many LEDs you should turn on. For a positive difference you divide by the storedA0 to 1023 value.
3:? problem: what is the the condition that will break the while loop at 2? letting go of the switch button?

If you want to do press once to start press agin to stop, then you need to review Reading buttons and debouncing (in software) and doing a simple 2 state engine code.

57  Using Arduino / Programming Questions / Re: MODBUS protocol. on: March 19, 2014, 06:43:17 am - result of a 15 second effort with google ...

And the hard work if this library doesnt do what you need to : (another 15 seconds with Google)

Good luck.
58  Community / Website and Forum / Re: Arduino Reference - abs() on: March 18, 2014, 07:00:56 am
Duh?  abs() is welbehaved and should not have any edge conditions.
Certainly this works
int z = 0; float zz = 0.0 ;
void setup() {
  Serial.begin(9600) ;
  zz =abs(z) ;  Serial.println(z) ;
  zz =abs(zz) ;  Serial.println(zz) ;

So start a new thread for discovering why your code hangs if the expression ((frequency - frequencyOld) / 20) returns zero. I guess that whatever code you do something with a step-size of zero has a logical flaw
59  Using Arduino / Programming Questions / Re: I wanna make a foosball scorer point counted everytime the ball goes in hole on: March 17, 2014, 04:17:58 pm
... cause there isn't anything online....
True. There is nothing online on "foosball scorer point counter with LCD " with readymade code and finished circuit diagrams and BOM (Bill Of Materials)

On the other hand there is gazillions of pages on how to interface an LCD to the Arduino, How to call the LCD library to write any text, How to connect a push button to the Arduino, How to read a pushbutton (debounce), How to use a photogate / photocell / lightbeam  with the Arduino ....

I'll even give you the code for incrementing a counter - forever smiley
Score = Score + 1 ;

When you have made some of your project and have a specific problem you can ask again, and I am sure somebody will help. But at the mement the question you ask is too vauge and open ended. I suggest you start with getting the Serial.print to show how often you push the button. Then add the LCD. Then replace the button with some lightsensor. Small steps, getting something to work as the project evolves.
60  International / Scandinavia / Re: Problem med PWM, transistor till led. on: March 17, 2014, 04:04:21 pm
@Kalevo: Nej det han har funkar - det ger värden mellan 0 og 255. Ditt förslag ger mellem -255 og +255. Prova. (Skriv ett litet program som skriver til Serial.print)

Pages: 1 2 3 [4] 5 6 ... 81