Recent Posts

Pages: 1 [2] 3 4 ... 10
11
I want two of my DC motors to be adjusted according to the thumbstick feedback. They will be on top of a hoverboard.

Thumbstick forward means:
Two engines running full speed running clockwise.

Thumbstick backward means:
Two engines running full speed counter clockwise

Thumbstick left means:
Right engine running full speed clockwise
Left engine stops

Thumbstick right means:
Left engine running full speed clockwise
Right engine stops

I used "if" statement. So if vertical value of thumbstick (0-1023) exceeds ~600 then run both engines forward and if it goes below ~450 then do the exactly opposite.

If horizontal value (0-1023) exceeds ~600 then stop the right engine, run left engine at full speed, if it goes below ~450, then do the exactly opposite.

Forward and backwards alone work well, same as left & right alone. But when I add all codes together motors confuse which order to follow. Because when I move thumbstick horizontally, i change vertical value as well, which triggers forward move.

I've been thinking really hard to come up with a solution but I got nothing so far. I can use 2 thumbsticks but seems to me like that won't solve my problem.

I need a code that will clearly distinguish horizontal and vertical commands. If one is triggered, the other one should stop immediately. Here's my code so far. I'd be glad if anyone with experience could contribute and improve it. Thanks a lot guys..!



Code: [Select]
int vert;
int horz;
int back;
int forward;
int right;
int left;

void setup(){
pinMode(10, OUTPUT); //Right motor forward (Coonected to L298N controller with H-bridge)
pinMode(11, OUTPUT); //Right motor backwards (Coonected to L298N controller with H-bridge)
pinMode (12, OUTPUT); //Left motor backwards (Coonected to L298N controller with H-bridge)
pinMode (13,OUTPUT); // Left motor forward (Coonected to L298N controller with H-bridge)
pinMode(3,OUTPUT); //Adjusts speed of left motor (PWM)
pinMode(5,OUTPUT); //Adjusts speed of right motor (PWM)
pinMode(18, INPUT); //Thumbstick vertical
pinMode(19, INPUT); //Thumbstick horizontal
 
 
}
void loop() {
vert = analogRead(18);
horz = analogRead(19);

//*************
//MOVE FORWARD
//*************
if (analogRead(vert) >=600 ) { 
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite (10, HIGH);
digitalWrite (11, LOW);
forward=map(vert, 600, 1023, 0, 50); //  Begins at 600, ends at 1023
forward = constrain(forward, 0, 50); // forces the number to be within 0-50 range.
analogWrite(3, forward);
analogWrite(5, forward);


}
//***************
//MOVE BACKWARD
//***************
if (analogRead(vert) <= 500) {
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite (10, LOW);
digitalWrite (11, HIGH);
back=map(vert, 500, 0, 0, 50); // Begins at 500, ends at 0.
back = constrain(back, 0, 50); // Forces the number to be within 0-50 range.
analogWrite(3, back);
analogWrite(5, back);
}


//***************
//TURN RIGHT
//***************
if (analogRead(horz) >= 600) {
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite (10, HIGH);
digitalWrite (11, LOW);
right=map(horz, 600, 1023, 0, 50); // Begins at 600, ends at 1023.
right = constrain(right, 0, 50); //Forces the number to be within 0-50 range.
analogWrite(3, 0);
analogWrite(5, right);

}

//**************
//TURN LEFT
//**************
if (analogRead(horz) <= 500) {
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
left=map(horz, 500, 0, 0, 50); // Begins at 500, ends at 0.
left = constrain(left, 0, 50); // Forces the number to be within 0-50 range.
analogWrite(3, left);
analogWrite(5, 0);

}

}
12
Arduino Due / Re: Spurious interrupts on Due
Last post by rstuart - Today at 11:11 pm
I am quite sure that these interrupts are not occurring because of the signal on the pin.  I won't go into great detail about all of the precautions I have taken but no matter how the signal is conditioned (even after first passing through another Arduino Pro!), the interrupts still occur.
13
Deutsch / Re: 3x MFRC522 per SPI verbin...
Last post by Serenifly - Today at 11:09 pm
Ok, kein Problem. Es ist wie ich gedacht hatte. Der CS Pin wird beim Konstruktor angegeben:
Code: [Select]

MFRC522(byte chipSelectPin, byte resetPowerDownPin);


Dann hast du für jedes Modul ein Objekt.


Siehe Beispiele für ein Modul:
Code: [Select]

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

Das kann man auch so schreiben:
Code: [Select]

MFRC522 mfrc522(10, 9);


Und so kannst du dir auch mehrere Objekte der MFRC522 Klasse anlegen, jeweils mit einem anderen CS/SS Pin.

Reset Pin braucht mal wohl auch, aber da wird auch einer für alle Module gehen.
14
Arduino Due / Re: Problem declared as input ...
Last post by PCWorxLA - Today at 11:08 pm
DDRx, PORTx and PINx are AVR registers. They do not work with Due (SAM). It's about to port your code from the platform AVR to SAM which is not a straightforward task.


The code (as posted) won't compile for an AVR based board either, you get the same error messages...
Code: [Select]
Arduino: 1.5.8 (Windows 8), Board: "Arduino Leonardo"

sketch_oct31a.ino: In function 'void setup()':
sketch_oct31a.ino:14:1: error: 'DDRL' was not declared in this scope
sketch_oct31a.ino: In function 'void loop()':
sketch_oct31a.ino:27:6: error: 'PORTL' was not declared in this scope
sketch_oct31a.ino:32:5: error: 'PORTL' was not declared in this scope
sketch_oct31a.ino:37:5: error: 'PORTL' was not declared in this scope
sketch_oct31a.ino:42:5: error: 'PORTL' was not declared in this scope
sketch_oct31a.ino:47:5: error: 'PORTL' was not declared in this scope
sketch_oct31a.ino:52:5: error: 'PORTL' was not declared in this scope
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Ralf
15
Français / Re: WS2801 + PNP + NPN
Last post by 68tjs - Today at 11:06 pm
Tu es sur que Rb est bien placée ?
Parce que si RB est câblée comme sur le dessin c'est normal que les led soit toujours dans le même état.
Le transistor NPN est toujours saturé.
La résistance doit être câblée entre la sortie du Ws machin et la base du transistor.

La datasheet on verra ça dans 12 jours  :smiley-mr-green:
16
Deutsch / Re: 3x MFRC522 per SPI verbin...
Last post by Whizzler83 - Today at 11:03 pm
https://github.com/miguelbalboa/rfid


ach du meinst das ich quasi jedes Modul einzel nacheinander abfrage bis eins antwortet?
17
Hey there!
I have a wii nunchuck and a couple of arduinos and xbee's. I am trying to send the Joystick X values over xbee to the other arduino with a xbee and to print it out to the serial monitor on my computer.

However i am getting a lot of junk on the serial monitor. And im not sure why.

Heres the code

Reciever:

Code: [Select]
void setup(){
 
  Serial.begin(9600);
 
}


void loop(){
 
 while (Serial.available() > 0){
   
   Serial.println(Serial.read() - '0');

 }
 
 
}



Transciever:

Code: [Select]
#include <Wire.h>
#include <Servo.h>
const int vccPin = A3;
const int gndPin = A2;

Servo servo;

const int dataLength = 6; // Number of bytes to request

static byte rawData[dataLength];

enum nunchuckItems {
  JoyX, JoyY, accelX, accelY, accelZ, btnZ, btnC};

void setup()
{
  pinMode(gndPin, OUTPUT);
  pinMode(vccPin, OUTPUT);
  digitalWrite(gndPin, LOW);
  digitalWrite(vccPin, HIGH);
  servo.attach(9);

  delay(1000);
  Serial.begin(9600);

  nunchuckInit();
}

void loop()
{
  nunchuckRead();

 
 
  int joyX = getValue(JoyX);
  Serial.println(joyX);
 
 

  }

  void nunchuckInit(){

    Wire.begin();
    Wire.beginTransmission(0x52);
    Wire.write((byte)0x40);
    Wire.write((byte)0x00);
    Wire.endTransmission();

  }

static void nunchuckRequest(){
  Wire.beginTransmission(0x52);
  Wire.write((byte)0x00);
  Wire.endTransmission();
}

boolean nunchuckRead(){

  int cnt = 0;
  Wire.requestFrom(0x52, dataLength);

  while (Wire.available()){

    rawData[cnt] = nunchuckDecode(Wire.read());
    cnt++;
  }

  nunchuckRequest();
  if (cnt >= dataLength)
    return true;
  else
    return false;

}


static char nunchuckDecode(byte x){
  return (x ^ 0x17) + 0x17;

}

int getValue(int item){

  if (item <= accelZ)
    return (int)rawData[item];
  else if (item == btnZ)
    return bitRead(rawData[5], 0) ? 0: 1;
  else if (item == btnC)
    return bitRead(rawData[5], 1) ? 0: 1;

}









Thank you and any suggestions will help!
18
Hi. I am working on a project sending data to a MYSQL server via sim900. Entering: http://xxxxxxxxx.com/web/insert.php?UNIT=2&DATE=20189&TIME=9801&TI=216&TO=2526 in a browser will update the server successfully.

The SIM900 is supposed to post this to a webpage and the variables will be stored.

By entering a sequence of AT commands the server updates the way it is supposed to do,
however when I run the AT sequence in code I get into trouble. The SIM900 throws "error"
after some of the AT commands and the sequence is not successful.

One of the things I notice when running the code is that the AT+HTTPPARA with "URL" and "HTTP://..." command get trunkated and the next line does not get the lf cr.

Here is the Arduino Code that I can not get to work corect:
Code: [Select]

/*
SIM900 minimum board from ITEAD STUDIO V1.0
Connected to Serial1 Arduino mega.

Entering AT commands via terminal give no errors and
sequence work without problems. The SIM900 then connect
to website and activate PHP script to update the dummy
variable to MYSQL dataserver for logging.

Running this code SHOULD be equivalent to manually entering
the AT commands, but it produces "error" results from SIM900.

Errors and success printout from the terminal listed below theis code.
first is from manual entering and second is from this code.


The AT+HTTPPARA="URL","http://xxxxx--->    gets trunkated in the middle
of the feedback print and the <cr><lf> is lost, hence the next AT-command
does not come on a new line.

*/

#define GPRS Serial1

void setup()
{
  pinMode(7,OUTPUT);digitalWrite(7,HIGH);
Serial.begin(9600);
GPRS.begin(9600);
Serial.println("Starting AT query in 15 seconds");
digitalWrite(7,LOW);   //toggle power pin low
delay(500);            //wait 500ms
digitalWrite(7,HIGH);  //toggle power pin back high
delay(14500);           //delay for sim900 to start up
Serial.flush();  GPRS.flush();  //remove the rdy message.
sendAT();        //start the AT sequence

}

void loop()
{
Serial.println("Looping Empty");
ShowSerialData();
delay(15000);

}

void sendAT()
{
  GPRS.print("AT+CREG?\r\n");   
  delay(5000);
  ShowSerialData();
   
  GPRS.print("AT+SAPBR\r\n");
  delay(5000);
  ShowSerialData();
 
  GPRS.println("AT+SAPBR=1,1\r\n");
  delay(5000);
  ShowSerialData();

  GPRS.println("AT+HTTPINIT\r\n"); 
  delay(5000);
  ShowSerialData();

  String mystring="AT+HTTPPARA=";mystring+='"';mystring+="URL";mystring+='"';
  mystring+=',';mystring+='"';mystring+="http:/";
  mystring+="/xxxxxxxxx.com/web/insert.php?UNIT=5402&DATE=201289&TIME=9801&TI=216&TO=2526";
  mystring+='"';mystring+='"';
 
  GPRS.print(mystring);
  GPRS.print("\r\n");
  delay(5000);
   ShowSerialData();

  GPRS.println("AT+HTTPACTION=0");
  delay(5000);
   ShowSerialData();

  GPRS.println("AT+HTTPREAD");//get local IP adress
  delay(5000);
  ShowSerialData();

  GPRS.println("AT+HTTPTERM");
  delay(5000);
  ShowSerialData();
}

void ShowSerialData()
{
  delay(50);
  while(!GPRS.available());
  if(GPRS.available()){
    while(GPRS.available()){
      Serial.write(GPRS.read());
    }
  }
}

Here is the Terminal printout from manually entering AT commandsequence with terminal:
Code: [Select]
AT+CREG?
+CREG: 0,1
OK
AT+SAPBR=2,1
+SAPBR: 1,3,"0.0.0.0"
OK
AT+SAPBR=1,1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://xxxxxxxxx.com/web/insert.php?UNIT=2&DATE=20189&TIME=9801&TI=216&TO=2526"
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPACTION=0
OK
+HTTPACTION:0,200,201
AT+HTTPREAD
+HTTPREAD:201
Connected successfully<BR>mysql_query(INSERT INTO `Data1`  (`UNIT_NAME`, `DATE`, `TIME`, `TEMP_IN`, `TEMP_OUT` ) VALUES ('x2','2012/8/9','9:8:01','21.6','25.26'))<BR>New record created successfully<BR>
OK
AT+HTTPTERM
OK

Here is the terminal printout from running the Arduino code with errors:
Code: [Select]
Starting AT query in 15 seconds

AT+CREG?
+CREG: 0,1
OK
AT+SAPBR
ERROR
AT+SAPBR=1,1
ERROR
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://xxxxxxxxx.com/web/insert.php?UNIT=540AT+HTTPACTION=0
ERROR
AT+HTTPREAD
OK
AT+HTTPTERM
OK

Looping Empty
19
Arduino Due / Re: Problem declared as input ...
Last post by Palliser - Today at 10:57 pm
DDRx, PORTx and PINx are AVR registers. They do not work with Due (SAM). It's about to port your code from the platform AVR to SAM which is not a straightforward task.

20
How can I build a system using 2 analog proximity switches to control a MOOG Hydraulic Servo valve.
One proximity has to read voltage to move in a positive direction and the other has to read in a negative direction. This has to move 1 axis in a balanced forward and reverse movement. Could I use a range finder? Total of the movement is 3". 
Pages: 1 [2] 3 4 ... 10