Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write Byte Error #1

Closed
eanmikale opened this issue Dec 27, 2017 · 31 comments
Closed

Write Byte Error #1

eanmikale opened this issue Dec 27, 2017 · 31 comments

Comments

@eanmikale
Copy link

Foremost, thank you for your work in the field. I have included our wiring below, for your reference. We also have followed the directions concerning installation of software, and upon execution of the sample, we are getting the following error message:

" Write Byte error: 121PCA9685 "

Any assistance would be greatly appreciated.

img_1418
img_1416
img_1417
img_1419

@jetsonhacks
Copy link
Owner

There's no information as to if the Jetson could actually see the PCA9685.
There is no information provided as to which Jetson you are using.
There is no information provided as to which version of L4T you are using.

Here's an article, did you do any of this: http://www.jetsonhacks.com/2016/01/26/jetson-racecar-part-3-esc-motor-control/

@eanmikale
Copy link
Author

We are using a Jetson TX2, with Jetpack 3.0, and L4T R27.1. I am including another screenshot from our attempt to detect the i2c device using the sudo i2cdetect -y -r 1 command.

screenshot from 2017-12-28 17-50-12

We are also working through the article you reference, but thought that the part 2 sequence of tutorials would be the first we would test. Thanks again.

@jetsonhacks
Copy link
Owner

jetsonhacks commented Dec 28, 2017

Note that this repository is for the NVIDIA Jetson TK1. As you can see from the i2cdetect in your image, the PCA9685 is not detected.

The Jetson TX1 and TX2 have different I2C bus numbering schemes, you may be able to find it on I2C bus 0, i.e.

$ sudo i2detect -y -r 0

The PCA9685 should be at location 0x40 in normal operation. However, I have not tested this . You can enumerate through the different I2C busses and try to find it.

@eanmikale
Copy link
Author

We have found success using the sudo i2cdetect -y -r 0 command.
successi2cdetect

We are still getting the following errors:
i2cscreenshotwriteerror

I understand this driver was created for the TK1, and not the TX2. I know you mentioned going on to the Part 3 tutorial. Do you believe we would be better moving onto the part 3? Thank you for your time.

@jetsonhacks
Copy link
Owner

How did you modify the code to use bus 0 instead?

@eanmikale
Copy link
Author

We did not change anything in the code outside of what was recommended, (i.e., removing the commented portions of the code for steering calibration.)

@jetsonhacks
Copy link
Owner

You might want to change the I2C bus (kI2CBus) of the PCA9685 object to be 0.
You should debug the code for your application.

@eanmikale
Copy link
Author

Will do. Will circle back once we are able to provide a log.

@michaelschleiss
Copy link

michaelschleiss commented Apr 23, 2018

I get the same "Write byte error". In my case the address is 70. I have already changed the bus to 0. But where in the code do I change the address from 40 to 70?

nvidia@tegra-ubuntu:~$ sudo i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: UU UU UU UU -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- UU -- -- UU                     

@jetsonhacks
Copy link
Owner

You set it when you initialize the PCA9685 instance. In the example code, ie:

PCA9685 *pca9685 = new PCA9685(0x70) ;

@galdalali
Copy link

HI @michaelschleiss, did you managed to solve this? I'm seeing only address of 70 like you and I still getting "Write byte error".
@eanmikale according to your description I believe you didn't plugged 3.3V to VCC.

Update: I didn't change the BUS to 0.. now it's working

@sharoseali
Copy link

hay guys .. I CONNECT MY PCA9685 WITH SERVO WHEN I RUN $ SUDO I2DETECT -Y -R 0 I GOT THIS
:....
screenshot from 2018-10-26 19-04-23

IS IT FINE .. when i run this script after making $ sudo make .. the servo donot show any response .. plz any one help... thanks in advance

@jetsonhacks
Copy link
Owner

jetsonhacks commented Oct 26, 2018

The PCA9685 is not available in the screenshot you show. Address 0x40 is being used by a previously installed kernel driver (probably the power monitors). You should connect the device to bus 1.

@sharoseali
Copy link

sharoseali commented Oct 26, 2018

to set device to bus 1 ... i have to write this command..$ SUDO I2DETECT -Y -R 1 .. or something else..
i am using TX2 ..

@jetsonhacks
Copy link
Owner

You have to wire the device appropriately. The command is correct.

@sharoseali
Copy link

ok jetsonhacks.. thanks for your help working time is over .so i will look in this tomorrow... again thanks...

@divyanshbabel
Copy link

I am using jetson tx2 PCA9685 is getting detected in address 0x40 on bus 1 but it keeps on giving "writeByte Error". I am using bluerobotics Basic ESC at 300 Hz and pwm values are also between 1100-1900
screenshot from 2018-10-27 19-24-56

@jetsonhacks
Copy link
Owner

jetsonhacks commented Oct 27, 2018

To use the I2C bus, you need to have the proper permissions. For example:

$ sudo ./servoExample

@jetsonhacks
Copy link
Owner

Write Byte error usually indicates that either the wiring is incorrect (the Jetson cannot see the PCA9685). Use the i2cdetect tool to determine if the device is visible.

The I2C bus requires root permission for access. If the Jetson can see the device, and you are receiving the "Write Byte" error, check to make sure that you are running using sudo, ie:

sudo ./servoExample

@sharoseali
Copy link

sharoseali commented Oct 27, 2018

jetsonhacks .hope u r having a good day..
i have successfully moved servo with TX2 by editing the C code in servoexample.cpp file. Now the issue is that i hve to controul servos from my python application. how can i controul that .. There are certain Adafruit libraries written in python but installation remain unsuccessful. any help please .

@jetsonhacks
Copy link
Owner

@sharoseali You will need to port the library to Python.

@sharoseali
Copy link

sharoseali commented Oct 28, 2018

thanks for your reply and soory for the late reply.....
sir, which library i have to use then ?? i have to generate pwm against particular situation by giving angles to rotate it so calling C code from python will not solve my problem..
controling servo from python is the problem

@jetsonhacks
Copy link
Owner

@sharoseali You should write Python code to control the servo.

@divyanshbabel
Copy link

thanks for the help but another problem came up it is not working means the thrusters are not rotating. I tried changing the frequency and PWM value but nothing happened, Than I changed the frequency in JHPWMDriver.cpp
from:
void PCA9685::setPWMFrequency ( float frequency ) {
printf("Setting PCA9685 PWM frequency to %f Hz\n",frequency) ;
float rangedFrequency = fmin(fmax(frequency,40),1000) ;
int prescale = (int)(25000000.0f / (4096 * rangedFrequency) - 0.5f) ;
// For debugging
// printf("PCA9685 Prescale: 0x%02X\n",prescale) ;
int oldMode = readByte(PCA9685_MODE1) ;
int newMode = ( oldMode & 0x7F ) | PCA9685_SLEEP ;
writeByte(PCA9685_MODE1, newMode) ;
writeByte(PCA9685_PRE_SCALE, prescale) ;
writeByte(PCA9685_MODE1, oldMode) ;
// Wait for oscillator to stabilize
usleep(5000) ;
writeByte(PCA9685_MODE1, oldMode | PCA9685_RESTART) ;
}

To:
void PCA9685::setPWMFrequency ( float frequency ) {
printf("Setting PCA9685 PWM frequency to %f Hz\n",frequency) ;
float rangedFrequency = fmin(fmax(frequency,40),1000) ;
int prescale = (int)(25000000.0f / 9600 - 0.5f) ;
// For debugging
// printf("PCA9685 Prescale: 0x%02X\n",prescale) ;
int oldMode = readByte(PCA9685_MODE1) ;
int newMode = ( oldMode & 0x7F ) | PCA9685_SLEEP ;
writeByte(PCA9685_MODE1, newMode) ;
writeByte(PCA9685_PRE_SCALE, prescale) ;
writeByte(PCA9685_MODE1, oldMode) ;
// Wait for oscillator to stabilize
usleep(5000) ;
writeByte(PCA9685_MODE1, oldMode | PCA9685_RESTART) ;
}
changed the PWM to:
while(pca9685->error >= 0 && getkey() != 27){

        pca9685->setPWM(0,0,1500) ;
        //pca9685->setPWM(1,0,servoMin) ;

        sleep(2) ;
        pca9685->setPWM(0,0,1700) ;
        //pca9685->setPWM(1,0,map(90,0,180,servoMin, servoMax)) ;
        sleep(2) ;
    }

and my pwm was 1700 so it sarted rotating but at 1500 it stopped. Motor was running in 1300 and 1500 only and for any other pwm it will remain stopped . Thank You Again for any suggestions.

@divyanshbabel
Copy link

printf("PCA9685 Device Address: 0x%02X\n",pca9685->kI2CAddress) ;
pca9685->setAllPWM(0,0) ;
pca9685->reset() ;
pca9685->setPWMFrequency(1500) ;
// 27 is the ESC key
int x=1100;
printf("Hit ESC key to exit\n");
while(pca9685->error >= 0 && getkey() != 27){
pca9685->setPWM(0,0,1500) ;
pca9685->setPWM(1,0,servoMin) ;
printf("off\n");
sleep(2) ;
x=x+50;
printf("%d",x);
pca9685->setPWM(0,0,x) ;
pca9685->setPWM(1,0,map(90,0,180,servoMin, servoMax)) ;
printf("on\n");
sleep(2) ;

this code is running properly with my thrusters and i am able to control the speed using pwm but i do not know the reason. Thank You in advance

@jetsonhacks
Copy link
Owner

I'm glad you got it to work. As noted in the example, that code is for controlling a servo motor, specifically a a Robot Geek RGS-13 Servo. ESCs are different. If you were perhaps to look at the more technical details of controlling your BESC, you would see:

Stopped | 1500 microseconds
Max forward | 1900 microseconds
Max reverse | 1100 microseconds

which might help explain your code.

@qiakeyufeiniao
Copy link

Hi @jetsonhacks , I met some strange problem when using the PCA9685 board.
It works fine following the setup by changing I2C bus number as 0 and address 0x70 for TX2.
But probably due to some mistaken power-off of the TX2 (while it is still connecting to PCA9685 with 5V power supply), after restart the TX2, the address using i2c tools show 0x71 and 0x72, the same as the result shown in "eanmikale commented on Dec 28, 2017". Running one program trying to use address 0x71, and the program will not write the address successfully, but the i2c checking result comes back to 0x70 after that running.
After the address is back to 0x70, the writing will not show "write Byte error", but when running the program, the PCA9685 does not successfully provide suitable signal anymore.

A quick small summary. At beginning PCA9685 controls RaceCar suitably, but after restart the TX2, address is changing to 0x71 0x72 using "sudo i2cdetect -y -r 0". Changing source code using "0x71" and run the program, the address is back to 0x70 using "sudo i2cdetect -y -r 0", but the program does not controls RaceCar anymore.

It is quite strange to me and I have no knowledge about it. Do you think the PCA9685 board is broken due to some bad usage?

@jetsonhacks
Copy link
Owner

I have not experienced this kind of issue. The address of the PCA9685 should be fixed, and not change. I am not sure why it would change to two addresses, that seems really strange. If you find the issue, please let us know.

@ghost
Copy link

ghost commented Aug 30, 2019

@qiakeyufeiniao I have a same problem with you. How did you solve it?

@rmeertens
Copy link

Same problem here, it actually occured with two PCA9685 boards of me. Would be great to know what causes it :)

@jungx148
Copy link

@qiakeyufeiniao I am having the exact same problem with several different PCA9685 boards by connecting with an Nvidia TX2 (with Orbitty carrier board).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants