Show Posts
Pages: [1]
1  Using Arduino / Installation & Troubleshooting / Problem with ServoLibrary on: February 16, 2014, 08:22:04 am
Hi,

I am currently trying to build a Quadrocopter based on the Arduino. The motors are controlled via Servo Library because the motorcontrollers listen to the same input signals as servos do.

Today I wanted to start my first Testflight and encountered a weird problem:

Whenever I have my Arduino connected to my Home PC (Windows smiley-cool the sketch works fine and the motors are properly started etc. But when I try to power the Arduino via another Computer (Laptop, Ubuntu) or directly with an external powersupply the motors don't react at all. The rest of the sketch works fine (LED blinks when I want it to, Serial output works on Ubuntu as well). Its only the Servo Library that seems to stop working.

Any ideas what might cause this? Unfortunately I dont have another Windows Computer here to test if it's Windows that works or just my specific computer.

This is the sketch that is running on the Arduino:
Code:
#include <Arduino.h>
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include "Wire.h"

#include "Ultrasonic.h"
#include <MegaServo.h>


//pins
#define LEDPIN 13
#define MOTOR0PIN 24
#define MOTOR1PIN 25
#define MOTOR2PIN 26
#define MOTOR3PIN 27
#define ULTRASONICPIN 28


// ================================================================
// ===               INTERRUPT DETECTION ROUTINE                ===
// ================================================================

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady() {
mpuInterrupt = true;
}


// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

//MPU data
MPU6050 mpu;
Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector
float yprDeg[3];

//Ultrasonic
Ultrasonic ultrasonic(ULTRASONICPIN);
long ultrasonicLastCheck = 0;
int height = 0;

MegaServo motor0, motor1, motor2, motor3;


//AI
bool motorsActive = false;
long motorLastWrite = 0;
int targetHeight = 20;
float targetYaw = 0, targetPitch = 0, targetRoll = 0;
int motorOffset = 956;
int motor0Offset, motor1Offset, motor2Offset, motor3Offset;
int motor0Speed, motor1Speed, motor2Speed, motor3Speed;




void setup() {
//init pins
pinMode(LEDPIN, OUTPUT);

//init communication
Serial.begin(115200);
Wire.begin();
TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)

//init sensors
mpu.initialize();
if (!mpu.testConnection())
{
while (true) {
delay(750);
digitalWrite(LEDPIN, HIGH);
delay(250);
digitalWrite(LEDPIN, LOW);
}
}
devStatus = mpu.dmpInitialize();

//init motors
motor0.attach(MOTOR0PIN);
motor1.attach(MOTOR1PIN);
motor2.attach(MOTOR2PIN);
motor3.attach(MOTOR3PIN);

motor0.writeMicroseconds(956);
motor1.writeMicroseconds(956);
motor2.writeMicroseconds(956);
motor3.writeMicroseconds(956);
digitalWrite(LEDPIN, HIGH);
delay(3000);
digitalWrite(LEDPIN, LOW);

if (devStatus == 0) {
mpu.setDMPEnabled(true);

attachInterrupt(0, dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();

dmpReady = true;

// get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
}
else {
Serial.print(devStatus);

while (true) {
delay(750);
digitalWrite(LEDPIN, HIGH);
delay(250);
digitalWrite(LEDPIN, LOW);
}
}
}


void loop() {

        if(Serial.available() > 0) {
                motorsActive = !motorsActive;
                while(Serial.available() > 0) {
                        Serial.read();
                }
        }
 
// wait for MPU interrupt or extra packet(s) available
while (!mpuInterrupt && fifoCount < packetSize) {

// check height every 200 ms
if (millis() - ultrasonicLastCheck > 200)
{
ultrasonicLastCheck = millis();
ultrasonic.DistanceMeasure();
height = ultrasonic.microsecondsToCentimeters();
/*
//output
Serial.print("height\t");
Serial.println(height);
*/
}

if (millis() - motorLastWrite > 50 && motorsActive)
{
motorLastWrite = millis();
// compute values for motors
yprDeg[0] = ypr[0] * 180 / M_PI;
yprDeg[1] = ypr[1] * 180 / M_PI;
yprDeg[2] = ypr[2] * 180 / M_PI;


if (height < targetHeight) {
motorOffset += 4;
}
else if (height > targetHeight) {
motorOffset -= 4;
}


if (yprDeg[0] > targetYaw) { // check yaw
motor0Offset += 4;
motor2Offset += 4;

motor1Offset -= 4;
motor3Offset -= 4;
}
else if (yprDeg[0] > targetYaw) {
motor0Offset -= 4;
motor2Offset -= 4;

motor1Offset += 4;
motor3Offset += 4;
}
                       
if (yprDeg[1] < targetPitch) { // check pitch
motor0Offset += 4;
motor3Offset += 4;

motor1Offset -= 4;
motor2Offset -= 4;
}
else if (yprDeg[1] > targetPitch) {
motor0Offset -= 4;
motor3Offset -= 4;

motor1Offset += 4;
motor2Offset += 4;
}

if (yprDeg[2] > targetRoll) { // check roll
motor0Offset += 4;
motor1Offset += 4;

motor2Offset -= 4;
motor3Offset -= 4;
}
else if (yprDeg[2] < targetRoll) {
motor0Offset -= 4;
motor1Offset -= 4;

motor2Offset += 4;
motor3Offset += 4;
}


motor0Offset = min(motor0Offset, 400);
motor0Offset = max(motor0Offset, -400);
motor1Offset = min(motor1Offset, 400);
motor1Offset = max(motor1Offset, -400);
motor2Offset = min(motor2Offset, 400);
motor2Offset = max(motor2Offset, -400);
motor3Offset = min(motor3Offset, 400);
motor3Offset = max(motor3Offset, -400);

motorOffset = min(motorOffset, 1600);
motorOffset = max(motorOffset, 956);

// write values to motors
motor0Speed = motorOffset + motor0Offset;
motor1Speed = motorOffset + motor1Offset;
motor2Speed = motorOffset + motor2Offset;
motor3Speed = motorOffset + motor3Offset;

motor0Speed = max(motor0Speed, 956);
motor1Speed = max(motor1Speed, 956);
motor2Speed = max(motor2Speed, 956);
motor3Speed = max(motor3Speed, 956);


                       
Serial.print(motor0Speed);
Serial.print("\t");
Serial.print(motor1Speed);
Serial.print("\t");
Serial.print(motor2Speed);
Serial.print("\t");
Serial.println(motor3Speed);
                       
                       
motor0.writeMicroseconds(motor0Speed);
motor1.writeMicroseconds(motor1Speed);
motor2.writeMicroseconds(motor2Speed);
motor3.writeMicroseconds(motor3Speed);
}

// if you are really paranoid you can frequently test in between other
// stuff to see if mpuInterrupt is true, and if so, "break;" from the
// while() loop to immediately process the MPU data
}

//handle interrupt

// reset interrupt flag and get INT_STATUS byte
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();


// get current FIFO count
fifoCount = mpu.getFIFOCount();

// check for overflow (this should never happen unless our code is too inefficient)
if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
// reset so we can continue cleanly
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));

// otherwise, check for DMP data ready interrupt (this should happen frequently)
}
else if (mpuIntStatus & 0x02) {
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

// read a packet from FIFO
mpu.getFIFOBytes(fifoBuffer, packetSize);

// track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;

// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

                if(!motorsActive) {
        //output (not working in visualmicro)
        Serial.print("ypr\t");
        Serial.print(ypr[0] * 180 / M_PI);
        Serial.print("\t");
        Serial.print(ypr[1] * 180 / M_PI);
        Serial.print("\t");
        Serial.println(ypr[2] * 180 / M_PI);
                }
}
}


Thanks for your help
2  Using Arduino / Networking, Protocols, and Devices / Error Arduino ADK - Android on: November 14, 2013, 05:55:28 pm
Hi,

I'm trying to make a connection between my Galaxy S3 and my Arduino ADK r3 work.
Until two months ago, everything worked as it was supposed to, but then I took a break from developing and now I wanted to give it another try. Only thing is it doesnt work anymore -.- I think I used the same code as before (not sure though) and I get this from the Arduino:
Code:
Device addressed... Requesting device descriptor.
found possible device. swithcing to serial mode
device supports protocol 1 or higher
Setup packet error: D
Device addressed... Requesting device descriptor.
found android acessory device
Can't get config descriptor length

I am using the Google ADK library for Arduino (found here: https://dl-ssl.google.com/android/adk/adk_release_20120606.zip)

The Arduino code:
Code:
#include <Ultrasonic.h>
#include <Wire.h>
#include <Servo.h>

#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

#define LEDPIN 13


// Communication with Android
#define RECV_LED 0
#define SEND_READY 0


AndroidAccessory acc(My Name,
                     "Quadrocopter",
                     "Quadrocopter",
                     "1.0",
                     "stuff",
                     "0000000012345678");


void setup()
{
  pinMode(LEDPIN, OUTPUT);
 
  Serial.begin(19200);

  delay(1000); // to avoid "OSCOKIRQ failed to assert"
 
  acc.powerOn();
 
  Serial.println("trying to connect");
  while(!acc.isConnected());
 
  byte ardReadyByte[1];
  ardReadyByte[0] = SEND_READY;
  acc.write(ardReadyByte, 1);

  Serial.println("setup done");
}

void loop()
{
  if (acc.isConnected()) {
    byte* msg = new byte[256];
    acc.read(msg, 256);
    Serial.println("received stuff");
    Serial.write(msg, 256);
    Serial.println();
   
    switch(msg[0]) {
      case RECV_LED:
      {
        uint8_t value = msg[1];
       
        analogWrite(LEDPIN, value);
        break;
      }
    }
  }
  else {
    digitalWrite(LEDPIN, HIGH);
    delay(100);
    while(!acc.isConnected());
    digitalWrite(LEDPIN, LOW);
  }
}

The "trying to connect" message comes through. The next thing is the error.

I hope someone can help. If anything is missing just ask.

Thanks
3  Using Arduino / Networking, Protocols, and Devices / Re: Arduino ADK r3 + Samsung Galaxy S3 on: January 13, 2013, 09:51:42 am
tada. found my mistake. i activated wifi debugging for my phone. this way it didn't communicate over usb at all. thanks for helping me find the mistake smiley
4  Using Arduino / Networking, Protocols, and Devices / Re: Arduino ADK r3 + Samsung Galaxy S3 on: January 13, 2013, 08:07:38 am
how exactly do i do that? im searching for the option the whole time but didnt find it
5  Using Arduino / Networking, Protocols, and Devices / Re: Arduino ADK r3 + Samsung Galaxy S3 on: January 13, 2013, 05:02:06 am
nobody any ideas?
6  Using Arduino / Networking, Protocols, and Devices / Arduino ADK r3 + Samsung Galaxy S3 on: January 11, 2013, 10:47:07 am
Hi there.

I'm currently trying to build a robot based on the Arduino Mega.
Now I wanted to expand my project by using an Arduino Mega ADK r3 + Samsung Galaxy S3 so I can use the S3's Wifi and sensor capabilities. Also I wanted to use the much faster processor and the mass storage inside the smartphone.

But trying this, I have encountered the problem, that my phone doesn't communicate with the ADK. The ADK's sample sketches to parse descriptors of usb devices works with mass-storages, mice or keyboards but my S3 seems not to be sending any data. It just uses the arduinos power to recharge.

Any ideas what I could be doing wrong?

Thanks
7  Using Arduino / Networking, Protocols, and Devices / Re: Problem w/ USB-Host Shield on: November 14, 2012, 12:18:05 pm
Mhm. Ya. Well I checked the solderings. If I'm not completely incompetent (which is possible, but I don't think so smiley-wink ) the solderings are okay.
And since I neither have an oscilloscope nor am from America (Germany) I think I just have to accept that it doesn't work. -.- Maybe I'll try to send it back to my supplier (lipoly)..



Thanks for your help!
8  Using Arduino / Networking, Protocols, and Devices / Re: Problem w/ USB-Host Shield on: November 13, 2012, 06:46:30 pm
Mhm. I checked the solderings. They are fine. The connection between the pins on the shield and the pins on the board are also established. So you are saying the shield's hardware is broken? or the ICSP on my Arduino?
9  Using Arduino / Networking, Protocols, and Devices / Re: Problem w/ USB-Host Shield on: November 13, 2012, 02:30:36 pm
Hi,

the result I get is the following:

Code:
Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register... Die revision invalid. Value returned: FF
Unrecoverable error - test halted!!
0x55 pattern is transmitted via SPI
Press RESET to restart test


But there is no error I could skip smiley-wink
10  Using Arduino / Networking, Protocols, and Devices / Re: Problem w/ USB-Host Shield on: November 13, 2012, 01:14:57 pm
Hi,

I've tested it with everything I could find here. USB-Sticks, Keyboards, Mice and my Android-Smartphone. Of course I used the example Sketches related to my device (Mass Storage, HID, ADK). But the error code appears always. Even if there is no device connected. As long as the shield is connected and powered up I get this error code.


Btw. Thanks for trying to help. You're the first one that does smiley-wink

TheJokerzz
11  Using Arduino / Networking, Protocols, and Devices / Re: Problem w/ USB-Host Shield on: November 13, 2012, 11:18:44 am
I dont have anything configured at all ('cause I didn't find instructions). The ICSP-Pins are connected. Here is an image:
12  Using Arduino / Networking, Protocols, and Devices / Problem w/ USB-Host Shield on: November 12, 2012, 02:12:18 pm
Hey,

I have a problem with my new usb host shield. I'm relatively new to the arduino platform, so I could use your help smiley-wink

Here it is:
I've bought a shield (http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino) and assembled it. I also checked the solderings. But when I attach it to my Arduino, it just gives no response. This is the example sketch I am running:
Code:
#include <avr/pgmspace.h>
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <hidboot.h>
#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>

class MouseRptParser : public MouseReportParser
{
protected:
virtual void OnMouseMove (MOUSEINFO *mi);
virtual void OnLeftButtonUp (MOUSEINFO *mi);
virtual void OnLeftButtonDown (MOUSEINFO *mi);
virtual void OnRightButtonUp (MOUSEINFO *mi);
virtual void OnRightButtonDown (MOUSEINFO *mi);
virtual void OnMiddleButtonUp (MOUSEINFO *mi);
virtual void OnMiddleButtonDown (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
    Serial.print("dx=");
    Serial.print(mi->dX, DEC);
    Serial.print(" dy=");
    Serial.println(mi->dY, DEC);
};
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
    Serial.println("L Butt Up");
};
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
    Serial.println("L Butt Dn");
};
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
{
    Serial.println("R Butt Up");
};
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
{
    Serial.println("R Butt Dn");
};
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
{
    Serial.println("M Butt Up");
};
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
{
    Serial.println("M Butt Dn");
};

USB     Usb;
USBHub     Hub(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE>    Mouse(&Usb);

uint32_t next_time;

MouseRptParser                               Prs;

void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");

    if (Usb.Init() == -1)
        Serial.println("OSC did not start.");
     
    delay( 200 );
 
    next_time = millis() + 5000;
 
    Mouse.SetReportParser(0,(HIDReportParser*)&Prs);
}

void loop()
{
  Usb.Task();
}
The only output I get is the initial "Start".

I did a little research and found that the Method Usb.getUsbTaskState gives me an error code 19, which is related to an error called "USB_DETACHED_SUBSTATE_ILLEGAL".

I am working with an Arduino Mega (ATMega 1280) and the Arduino Library by "Circuits@Home" (https://github.com/felis/USB_Host_Shield_2.0).

I would be very grateful if you could help me!

PS: If you need more information, just tell me.
PPS: aaand forgive me if my english is bad -.-
13  International / Deutsch / Problem mit USB-Host Shield on: November 09, 2012, 05:58:14 am
Hi,

ich habe mir letzte Woche eine USB-Host Shield (http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino) für meinen Arduino Mega(ATMega 1280) gekauft. Die Pins habe ich alle angelötet und die Lötstellen (soweit möglich) überprüft.

Jetzt habe ich allerdings das Problem, dass der Arduino anscheinend keinerlei Geräte erkennt, die ich an ihn anschließe. Bei der zum Shield gehörenden Library sind einige Beispielprogramme dabei, die allerdings alle nicht funktionieren.
Da stellt sich mir natürlich die Frage nach der Fehlerursache. Da ich noch nicht soo lange mit dem Arduino arbeite, dachte ich mir, dass ich hier nochmal frage, ob vielleicht schonmal jemand mit dem USB-Shield gearbeitet hat und sich damit auskennt.

Hier noch das Beispielprogramm:
Code:
#include <avr/pgmspace.h>
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <hidboot.h>
#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>

class MouseRptParser : public MouseReportParser
{
protected:
virtual void OnMouseMove (MOUSEINFO *mi);
virtual void OnLeftButtonUp (MOUSEINFO *mi);
virtual void OnLeftButtonDown (MOUSEINFO *mi);
virtual void OnRightButtonUp (MOUSEINFO *mi);
virtual void OnRightButtonDown (MOUSEINFO *mi);
virtual void OnMiddleButtonUp (MOUSEINFO *mi);
virtual void OnMiddleButtonDown (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
    Serial.print("dx=");
    Serial.print(mi->dX, DEC);
    Serial.print(" dy=");
    Serial.println(mi->dY, DEC);
};
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
    Serial.println("L Butt Up");
};
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
    Serial.println("L Butt Dn");
};
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
{
    Serial.println("R Butt Up");
};
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
{
    Serial.println("R Butt Dn");
};
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
{
    Serial.println("M Butt Up");
};
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
{
    Serial.println("M Butt Dn");
};

USB     Usb;
USBHub     Hub(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE>    Mouse(&Usb);

uint32_t next_time;

MouseRptParser                               Prs;

void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");

    if (Usb.Init() == -1)
        Serial.println("OSC did not start.");
     
    delay( 200 );
 
    next_time = millis() + 5000;
 
    Mouse.SetReportParser(0,(HIDReportParser*)&Prs);
}

void loop()
{
  Usb.Task();
}

Die einzige Ausgabe die ich am Rechner erhalte ist "Start".
Pages: [1]