MeGyro Port?


#1

I need some help here:
I downloaded the latest library (V2.1.0422) and connected my new MeGyro module. In the example code there is no call to witch port I want to connect to? I uploaded the example code without errors, but nothing seems to happen. In the example code the call for the module is just: “MeGyro gyro;”. Any other module will use a code like: “MeInfraredReceiver IRreceiver(PORT_6);”. I had a look in the header file “Makeblock.h” and the line like: “MeGyro(uint8_t port);” seems to miss. Can I just add that one? If it works, it will have to be included in the next update.

Any comments on this?


#2

Hi @Heine_Ravnholt,

Our engineer @indream is on the holiday now and he will come back on Monday. I will ask him check this problem ASAP. Can you try to add the PORT_X by yourself first?


#3

I tried to change it myself, but it did not work. I took a look into the Makeblock.cpp file too and think I found the answer to why we don’t have to tell witch port to use. The Gyro uses the Wire library and I guess it will make a search for any modules when we write gyro.begin().

Then why does the example code not work (no output on serial monitor)? I tracked it to the call for Serial.available(). When I remove the if statement, and just use a delay(100) between gyro.update() I get readings on my serial monitor.

I searched for the answer in SoftwareSerial resources and found this:

You can’t write code like this:

void loop()
{
  device1.listen();
  if (device1.available() > 0)
  {
    int c = device1.read();
    ...
  }
  device2.listen();
  if (device2.available() > 0)
  {
    int c = device2.read();
    ...
  }
}

This code will never do anything but activate one device after the other.

The example code does not call any other device than Serial, so I don’t know why the problem occur, but I can see that something like this is what happens.

So this edited example code will work:

#include "Makeblock.h"
#include <Wire.h>
#include <SoftwareSerial.h>
MeGyro gyro;
void setup(){
  gyro.begin();
}
void loop(){
  gyro.update();
  Serial.read();
  Serial.print("X:");
  Serial.print(gyro.angleX());
  Serial.print(" Y:");
  Serial.print(gyro.angleY());
  Serial.print(" Z:");
  Serial.println(gyro.angleZ());
  delay(100);
}

#4

Yes,the gyro module is based on MPU6050 using I2C communication.
IRreceiver use softwareserial, but the port6-8 can’t support software serial on the baseboard,so the library use a polling method to simulate serial when using port6-8.


#5