dgatf / msrc

Multi Sensor for RC with RP2040 - FrSky D, SmartPort, XBUS, SRXL, IBUS, SBUS, Multiplex Sensor Bus, Jeti Ex Bus, Hitec
GNU General Public License v3.0
169 stars 41 forks source link

Atmega2560 pins #22

Closed stefaanbolle closed 3 years ago

stefaanbolle commented 3 years ago

In your table I notice: ESC serial RX1 GPS RX2 PWM out 7 S.port/SRXL 4/12 XBUS/sensor SDA20 XBUS/sensor SCL21

What pins do you mean on a Mega2560 Pro Mini board because I do not find these pin references on my board https://pg-cdn-a2.datacaciques.com/00/NDAy/19/01/02/r4tvb3u808096tbn/ab2ddc6ef3b8ad95.jpg

stefaanbolle commented 3 years ago

Found the pin mapping I guess https://robotdyn.com/pub/media/0G-00005642==MEGA-PROMINI-ATmega2560/DOCS/PINOUT==0G-00005642==MEGA-PROMINI-ATmega2560.pdf

dgatf commented 3 years ago

I've improved the pin table with usual pin numbers

ATmega250 pinout

Which rx protocol are you using? smartport, xbus, srxl?

Are you attaching a esc serial or castle?

stefaanbolle commented 3 years ago

I am using a Radiomaster R161. Smart port wire and VCC and GND go to the Mega2560 pin VCC/GND and D4/D12 with pullup). S.Bus + VCC and GND go to FBL msrc.lua does not detect the board and no sensors are detected. Was working with 328P pro micro before. Are ports D4 and D12 (4 and 12) the correct ones for smartport?

dgatf commented 3 years ago

There was an error on the readme. Fixed. Correct pins for ATmega2560 are 10 and 15

castle_atmega2560_smartport_2

stefaanbolle commented 3 years ago

Thanks, will try it out

stefaanbolle commented 3 years ago

Indeed, much better now :-)

stefaanbolle commented 3 years ago

Is it correct that BN-220 GPS TX goes to pin D17 on Mega2560? I do get a GPS signal (VCC is connected to 5V and GND to GND) but the coordinates are garbage as are the other GPS values. Same applies for BMP280 ALT value

dgatf commented 3 years ago

Yes, D17 is the correct pin for GPS. Be sure you have set the default baud rate 9600

I'll check GPS and BMP280 for ATmega2560 in the following days

stefaanbolle commented 3 years ago

Yes, D17 is the correct pin for GPS. Be sure you have set the default baud rate 9600

I'll check GPS and BMP280 for ATmega2560 in the following days

Do I have to set baudrate in your code somewhere?

dgatf commented 3 years ago

If you are using other baud rate than the default 9600 in BN220 you can change its baud rate (with ucenter app from ublox) or you can change line 450 in smartport.cpp

GPS_SERIAL.begin(9600);

with the desired baud rate

Edit: added _GPS_BAUDRATE to config.h, line 23. You can adjust the GPS baud rate in config.h

dgatf commented 3 years ago

To debug the gps, download latest code as debug for gps was broken

Enable gps debug in config.h, line 119:

#define DEBUG_GPS

and post the output (with serial monitor at 115200)

dgatf commented 3 years ago

Please download latest code: now all gps values are initialized to 0 so you won't get garbage values if there is no data input from the gps

dgatf commented 3 years ago

Same applies for BMP280. You were getting garbage values because BMP280 is not communicating with Arduino

Now I've updated the code so altitude will be 0 even if there is no data input from BMP280. Note that the default I2C address for BMP280 is 0x77, but also can be 0x76

Download latest code and review connections and config

dgatf commented 3 years ago

For BMP280 there was an issue with the altitude calculation. Fixed

dgatf commented 3 years ago

Date/time and lat/log values were twisted. Fixed Also altitude is now limited to values bigger than 0

stefaanbolle commented 3 years ago

GPS looks OK now, still 0m with BMP280 (address 76 since pin determining address is not connected to anything) I'll continue investigating

dgatf commented 3 years ago

Do you get a valid value for bmp280 temperature at sensor Tmp1 (0x401)?

Altitude is 0m at ground

stefaanbolle commented 3 years ago

temp is 0 deg alt = 0m

stefaanbolle commented 3 years ago

Seems BMP is not working. Connection is straaight forward if SCL and SDA pins are corresponding in schema vs code

dgatf commented 3 years ago

If you are using lua for config, i2c address is in decimal, 0x76 is 118 and 0x77 is 119

And connect BMP_Vcc to 3.3v and BMP_GND to GND

stefaanbolle commented 3 years ago

Hmm, address might be wrong indeed

stefaanbolle commented 3 years ago

Since the last commit I do notice when clicking update in LUA, UPDATING takes forever. Wi have to stop it with ret key on TX. When restarting msrc.lua, values are retained.

dgatf commented 3 years ago

There was a bug in the lua script that was causing wrong I2C config. Please upload the latest lua script to the radio, update config and check if BMP is working

dgatf commented 3 years ago

Since the last commit I do notice when clicking update in LUA, UPDATING takes forever. Wi have to stop it with ret key on TX. When restarting msrc.lua, values are retained.

Fixed. Please flash latest code

stefaanbolle commented 3 years ago

Updating still keeps flashing. I have to quit it with return. Alt and Tmp1 remains 0. Awaiting new sensor module which should arrive any day now. Will swap module to try this option.

dgatf commented 3 years ago
  1. Could you flash the latest code and enable in config.h:

    #define DEBUG_EEPROM_WRITE
    #define DEBUG_EEPROM_READ

    And post the result when booting and also when updating from lua

  2. Disable the previous and enable #define DEBUG and post the output when updating from lua

dgatf commented 3 years ago

Sorry, now is updated for debug

stefaanbolle commented 3 years ago

Can I connect both the S.Port connector and the usb connector to the Mega2560 board at the same time to output the debug? Won't overload board nor PC USB Port? Just to be sure

dgatf commented 3 years ago

Disconnect Vcc from smartport, keep only GND and data lines

stefaanbolle commented 3 years ago
1. Could you flash the latest code and enable in _config.h_:
#define DEBUG_EEPROM_WRITE
#define DEBUG_EEPROM_READ

Gives V0.8.0 RC Pr:4 As:0 Gp:1 V1:1 V2:0 Cu:1 T1:0 T2:0 Po:1 rR:10 rV:10 rC:10 rT:10 aR:3 aV:3 aC:3 aT:3 I1:1 A1:118 I2:2 A2:0 RC Pr:4 As:0 Gp:1 V1:1 V2:0 Cu:1 T1:0 T2:0 Po:1 rR:10 rV:10 rC:10 rT:10 aR:3 aV:3 aC:3 aT:3 I1:1 A1:118 I2:2 A2:0 9⸮&⸮$⸮⸮⸮ą⸮⸮R⸮⸮⸮vq⸮⸮M'⸮)t6⸮H⸮ɉ⸮⸮⸮⸮⸮⸮ V0.8.0 RC Pr:4 As:0 Gp:1 V1:1 V2:0 Cu:1 T1:0 T2:0 Po:1 rR:10 rV:10 rC:10 rT:10 aR:3 aV:3 aC:3 aT:3 I1:1 A1:118 I2:2 A2:0 RC Pr:4 As:0 Gp:1 V1:1 V2:0 Cu:1 T1:0 T2:0 Po:1 rR:10 rV:10 rC:10 rT:10 aR:3 aV:3 aC:3 aT:3 I1:1 A1:118 I2:2 A2:0

And post the result when booting and also when updating from lua

1. Disable the previous and enable `#define DEBUG` and post the output when updating from lua

gives a lot, but when clicking update I get M+ <F:31 D:5000 V:AAAA96F1 <F:31 D:5000 V:43333F2 <F:31 D:5000 V0.8.0 after that it remains UPDATING and no further debug output

dgatf commented 3 years ago

I2C config seems good (I1:1 A1:118). You could try with address 119 (0x77), just in case

The arduino is rebooting when updating from lua. That's why lua keeps trying to update

dgatf commented 3 years ago

Fixed the updating forever issue with lua. There was an issue deleting objects

Please try latest code

dgatf commented 3 years ago

I've got BMP280 working at 0x76. I recommend to test BMP280 with a specific sketch (that you can find in some arduino libraries). You may need to replace the sensor. Remember to connect BMP Vcc to 3.3v, not 5v

stefaanbolle commented 3 years ago

Thanks, will try with a new sensor. Should arrive in the mailbox any moment now

stefaanbolle commented 3 years ago

The LUA on the Transmitter works well again. The BMP280 (a brandnew one) does not give any telemetry data via I2C. It is connected to GND - GND SDA - D20 SCL - D21 3V3 - 3V3

In LUA on TX I sellect I2C1 as BMP280 and address 118/119 (tried both) TMP1 and ALT remain both 0

dgatf commented 3 years ago

Please flash _i2cscan.ino (in tools folder) to check circuit and BMP module. No need to power the receiver or anything else

In serial monitor at 115200, you should see:

I2C scanner
76
Done

Where 76 is the address in hex. If no number, there is an issue with the circuit or the module

If you see the address, disconnect smartpoft Vcc, flash msrc.ino again enabling debug #define DEBUG and post the output

stefaanbolle commented 3 years ago

Will have to search, BMP is brand new

I2C scanner
Done

D20 - SDA and D21 - SCL are correct right?

dgatf commented 3 years ago

Yes, correct. Be sure they are not interchanged (try interchanging them just un case). Dont use long wires. It looks like a circuit issue

dgatf commented 3 years ago

I see you are using a HW v5 LH ESC. Could you post the ESC signature by enabling #debug DEBUG_ESC_HW_V4 It will appear before raising throttle and the output is S: and some hex values. I'm trying to autodetect the ESC model to adjust sensor transformations Are you getting correct values for the current? Thanks

stefaanbolle commented 3 years ago

Actually I use a HW V4 => my config was wrong

stefaanbolle commented 3 years ago

Running out of ideas. Swapped SDA and SCL, same result. The BMP gets 3,3V Wires are 7cm

dgatf commented 3 years ago

Do you have another Arduino to test with?

dgatf commented 3 years ago

Could you post a picture or a link to your bmp280 module?

dgatf commented 3 years ago

Your module may be stuck in SPI mode I've modified the I2C scanner to loop every 3sec Flash the updated _i2cscan.ino. To select I2C mode, CS pin must be high (3.3v) at startup (connect the pin before power up). I believe you can disconnect the pin after bootup and needs to be done only once

stefaanbolle commented 3 years ago

There is no CS pin on the module VCC - GND - SCL - SDA - CS0 and SD0

dgatf commented 3 years ago

CS=CS0

stefaanbolle commented 3 years ago

CS=CS0 CSB I meant. Tried that one, same result

dgatf commented 3 years ago

Maybe a picture of the circuit you made will help

stefaanbolle commented 3 years ago

See attached. The yellow wire is going to D20 - SDA and the blue to D21 - SCL VCC to 3.3V and GND to GND on the Mega2560 board.

20210312_154006 20210312_154013

dgatf commented 3 years ago

Looks ok... don't know what else...

You can try connecting SD0 to GND or 3.3V. This defines the address (0x76, 0x77). With CSB disconnected or to 3.3v

You can try 5V version of BMP280, which is 4 pins and only I2C. Though I'm using the same board as you, 3.3v 6 pins, without any issue

Try with another Arduino