[SOLVED] Selecting an ultrasonic sensor and interface

Firmware/software/electronics/mechanics
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by tobias »

I'm on my mobile so it will be a bit short answer. Since the ext I2C is on anothet I2C bus you need to initialize it. Have a look in imu.c to see how it is done for the other i2c bus.
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by alex »

tobias wrote:I'm on my mobile so it will be a bit short answer. Since the ext I2C is on anothet I2C bus you need to initialize it. Have a look in imu.c to see how it is done for the other i2c bus.
Ok, corresponding to your advice I've rewritten my code and placed it in a separate file mb1242.c. Where do I have to put this:

Code: Select all

i2cdevInit(I2C2);
mb1242Init(I2C2);
If I place the I2C initialization (I2C2, correct?) in stabilizerInit(), the copter stops responding after startup and the red/green LEDs won't flash normally but simply stay dark.
I don't have HAL functions implemented so far, so there isn't something like imu6Init() for initializing.

Can you help me out? Thanks for putting me on the right track, tobias. :idea:
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by tobias »

The problem might be that you are not running the latest FW where there was a bug in the i2cdevInit? Do you have your repo on github so I can have a look at your code?
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by alex »

tobias wrote:The problem might be that you are not running the latest FW where there was a bug in the i2cdevInit? Do you have your repo on github so I can have a look at your code?
I pushed the changes to my own fork: https://github.com/alexriegel/crazyflie ... nar-mb1242.
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by alex »

Any idea, tobias? My fork should be up-to-date.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by arnaud »

Tobias is on vacation so I had a look. Do you still have problems? I pulled your branch, compiled and the copter starts normally. I see that your latest commit corrects the I2C address so I assume something is working, or?
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by alex »

arnaud wrote:Tobias is on vacation so I had a look. Do you still have problems? I pulled your branch, compiled and the copter starts normally. I see that your latest commit corrects the I2C address so I assume something is working, or?
Thanks for taking over, arnaud.

No, my copter still doesn't initialize normally - as stated above. After switching it on, the copter isn't responding and the red LED stays dark. With the standard firmware everything's fine. :? It seems like my copter doesn't get far enough, so I have no chance to verify the address thing.

Is my I2C2 initialization code correct? The I2C2 interface is the right choice if the device is connected to the expansion header, isn't it?! Can I find this correlation somewhere in the documentation or do I have to simply know it?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by arnaud »

The best to see which I2C is used is the schematic: http://wiki.bitcraze.se/_media/projects ... _rev.f.pdf so yes the expansion port I2C is I2C2.

As for the crash at startup I do not see it, when flashing program from your branch my Crazyflie starts normally. It may be related to the presence of the I2C device. The best would be to see where it crash exactly, do you have a jtag debuger? Otherwise I would use the leds: lighting up led at different stage to see what is making program crash.

I see one point where it could block because of the hardware: i2cdev.c:347, https://github.com/bitcraze/crazyflie-f ... dev.c#L347
If for some reason SDA is low it will never leave the i2cdevInit function.
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by alex »

arnaud wrote:As for the crash at startup I do not see it, when flashing program from your branch my Crazyflie starts normally. It may be related to the presence of the I2C device. The best would be to see where it crash exactly, do you have a jtag debuger? Otherwise I would use the leds: lighting up led at different stage to see what is making program crash.
No, I don't have a jtag debugger.
I should have stated the startup behaviour more precisely: the motors are spinning up synchronously as they are supposed to be. Afterwards, both the red and the green LED are blinking for about half a second before they stay dark in the end. The blue LED is on all the time. Does this help? If not, I have to try your "debugging" trick with the LEDs.
arnaud wrote:I see one point where it could block because of the hardware: i2cdev.c:347, https://github.com/bitcraze/crazyflie-f ... dev.c#L347
If for some reason SDA is low it will never leave the i2cdevInit function.
Ok, I see. For what reason should the SDA line stay low unexpectedly? Can't get the point somehow... :oops:
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Hover] Selecting an ultrasonic sensor and interface

Post by arnaud »

This sounds like it is crashing somewhere when reading the sensor. It could help to look at the I2C lines to see if there is any communication going on. Also lighting up an LED just before reading a range value and lighting off just after will tell you if it crashes in this part of the code or somewhere else. Also a random though: try to increase the stack size of the task that runs your code. Having a stack overflow there it typically the kind of thing that would crash the copter.
Ok, I see. For what reason should the SDA line stay low unexpectedly? Can't get the point somehow... :oops:
The point is that SDA should not be pulled low. If it would happen it would most likely be a cabling or hardware error. But as the copter is passing the self-test this is not it.
Post Reply