Go Down

Topic: Maxbotix UltraSonic sensor I2C problem (Read 169 times) previous topic - next topic

Abdulaziz14

Hi

I have a Project for my graduation in College. It's about Smart Water Tank. The idea is to try to implement as many sensors as we can - as a group - that relate to our studies in Electrical Engineering. We have more than one problem. I don't know if I can post them all but it will be confusing. So, I will only explain this problem in this topic.

I'm using I2C Maxbotix Ultrasonic sensor ( MB7247 ) to measure the level of the water. I'm using Mega 2560. They provided the code for it, but it was for the UNO. I'm not good at programming, but I tried to use this sensor with Mega and yes I did change the pins ( SDA 20 and SCL 21) to match it to Mega. That didn't work when I upload the code. I don't know if I need to also change PORTC:

Code: [Select]
#define SCL_PIN 5              //Default SDA is Pin5 PORTC for the UNO -- you can set this to any tristate pin
#define SCL_PORT PORTC
#define SDA_PIN 4              //Default SCL is Pin4 PORTC for the UNO -- you can set this to any tristate pin
#define SDA_PORT PORTC


So, I changed them to Pin 0 , Pin 1 respectively. Are those AN pins to be sure ?
I got to upload the code fine, but I got these results.
Code: [Select]
Polling addresses...
Couldn't start:2
Couldn't start:4
Couldn't start:6
Couldn't start:8
Couldn't start:10
Couldn't start:12
Couldn't start:14
Couldn't start:16
Couldn't start:18
Couldn't start:20
Couldn't start:22
Couldn't start:24
Couldn't start:26
Couldn't start:28
Couldn't start:30
Couldn't start:32
Couldn't start:34
Couldn't start:36
Couldn't start:38
Couldn't start:40
Couldn't start:42
Couldn't start:44
Couldn't start:46
Couldn't start:48
Couldn't start:50
Couldn't start:52
Couldn't start:54
Couldn't start:56
Couldn't start:58
Couldn't start:60
Couldn't start:62
Couldn't start:64
Couldn't start:66
Couldn't start:68
Couldn't start:70
Couldn't start:72
Couldn't start:74
Couldn't start:76
Couldn't start:78
Couldn't start:80
Couldn't start:82
Couldn't start:84
Couldn't start:86
Couldn't start:88
Couldn't start:90
Couldn't start:92
Couldn't start:94
Couldn't start:96
Couldn't start:98
Couldn't start:100
Couldn't start:102
Couldn't start:104
Couldn't start:106
Couldn't start:108
Couldn't start:110
Couldn't start:112
Couldn't start:114
Couldn't start:116
Couldn't start:118
Couldn't start:120
Couldn't start:122
Couldn't start:124
Couldn't start:126
Couldn't start:128
Couldn't start:130
Couldn't start:132
Couldn't start:134
Couldn't start:136
Couldn't start:138
Couldn't start:140
Couldn't start:142
Couldn't start:144
Couldn't start:146
Couldn't start:148
Couldn't start:150
Couldn't start:152
Couldn't start:154
Couldn't start:156
Couldn't start:158
Couldn't start:160
Couldn't start:162
Couldn't start:164
Couldn't start:166
Couldn't start:168
Couldn't start:170
Couldn't start:172
Couldn't start:174
Couldn't start:176
Couldn't start:178
Couldn't start:180
Couldn't start:182
Couldn't start:184
Couldn't start:186
Couldn't start:188
Couldn't start:190
Couldn't start:192
Couldn't start:194
Couldn't start:196
Couldn't start:198
Couldn't start:200
Couldn't start:202
Couldn't start:204
Couldn't start:206
Couldn't start:208
Couldn't start:210
Couldn't start:212
Couldn't start:214
Couldn't start:216
Couldn't start:218
Couldn't start:220
Couldn't start:222
Couldn't start:224
Couldn't start:226
Couldn't start:228
Couldn't start:230
Couldn't start:232
Couldn't start:234
Couldn't start:236
Couldn't start:238
Couldn't start:240
Couldn't start:242
Couldn't start:244
Couldn't start:246
Couldn't start:248
Couldn't start:250
Couldn't start:252
Couldn't start:254
Address polling complete.
Take a reading at the default address
Change the sensor at the default address to 222
Take a reading at the new address
Change the sensor back to the default address


I used 4.7K resistors,2K resistors. Same problem. Used nothing and I got same result but the difference is only in the speed of polling address "Couldn't start" are slower. Must mean something.

I want your help in this problem and others, but for now I want to make it work.
Thank you in advance

Notes:

Here is the link to the datasheet

The code


jremington

#1
Oct 06, 2017, 08:00 pm Last Edit: Oct 06, 2017, 08:02 pm by jremington
Those aren't Arduino pin numbers; they are hardware pin numbers for PORTC, SCL and SDA on the Uno.
The corresponding I2C pins are PORTD pin 0 (SCL) and PORTD pin 1 (SCA) on the 2560.

DrDiettrich

It's not a good idea to use any but the standard Wire library to support as many different i2C devices as you like. Why use a software I2C library if a hardware I2C connection is available on every Arduino? See the Wire library examples for scanning I2C devices and more. Add the specific parts of the MaxSonar library to your sketch.

Abdulaziz14

Those aren't Arduino pin numbers; they are hardware pin numbers for PORTC, SCL and SDA on the Uno.
The corresponding I2C pins are PORTD pin 0 (SCL) and PORTD pin 1 (SCA) on the 2560.
Sorry, I worked on this for 2 months and got confused with the files. Apparently I changed them to PORTD. I believe I got same results, but I will try to confirm this again when I get the chance perhaps tomorrow.

For connecting wires, pin 0 (SCL ) is pin 0 ( AN ) on the board ? as I said I'm not good at this.

Can you give me a link to explain what are PORTC PORTD and the relation to their pins on board?

It's not a good idea to use any but the standard Wire library to support as many different i2C devices as you like. Why use a software I2C library if a hardware I2C connection is available on every Arduino? See the Wire library examples for scanning I2C devices and more. Add the specific parts of the MaxSonar library to your sketch.
This is their reasoning
https://www.maxbotix.com/articles/095.htm

What do I need to change to make it for Wire ? I would appreciate the help.

Will this conflict with other sensors using Wire libraries ?

DrDiettrich

The sensor has a really poor design, if it requires a special library for its crippled I2C interface. Be prepared for trouble with any other hardware, that needs attention while a communication with the sensor is going on.

I'd use a sensor with a different interface. RS232 should be easier to use, then you can connect the sensor to one of the free Serial ports of the Mega (Serial1-3).

Abdulaziz14

The sensor has a really poor design, if it requires a special library for its crippled I2C interface. Be prepared for trouble with any other hardware, that needs attention while a communication with the sensor is going on.

I'd use a sensor with a different interface. RS232 should be easier to use, then you can connect the sensor to one of the free Serial ports of the Mega (Serial1-3).
It is an expensive sensor and can't afford to get another. I would like see it running first. Else is a problem for another day.

Also, is it possible to use to 2 Mega for my project with this sensor being on just one Mega board while the others for the rest ? or that just complicated more ?

DrDiettrich

You can use any small Arduino (Mini...) for dealing with that sensor, a Mega is not required for that purpose. Then you can read the sensor and transfer the data alternately, without any possible trouble caused by the sensor library. The Pro Mini uses the same controller than the Uno, for other controllers you may have to adapt the pin numbers in the library as appropriate.

Abdulaziz14

Those aren't Arduino pin numbers; they are hardware pin numbers for PORTC, SCL and SDA on the Uno.
The corresponding I2C pins are PORTD pin 0 (SCL) and PORTD pin 1 (SCA) on the 2560.
I couldn't try it this week. but I believe it has the same problem.

You can use any small Arduino (Mini...) for dealing with that sensor, a Mega is not required for that purpose. Then you can read the sensor and transfer the data alternately, without any possible trouble caused by the sensor library. The Pro Mini uses the same controller than the Uno, for other controllers you may have to adapt the pin numbers in the library as appropriate.
It is just that I have an extra Mega.

Is this the right section to ask about the code or it is in the programming section ?

I create a new topic ?

DrDiettrich

Continue this thread and present your code.

Go Up