Tschucker / ArduinoBLE-Cycle-Power-Service

Implements the BLE Cycle Power Service on Arduino Nano 33 BLE Sense using Magnetometer Sensor
MIT License
25 stars 5 forks source link

No measurement or no signal #2

Open Stephan296 opened 2 years ago

Stephan296 commented 2 years ago

Thx for your great project. But when i try to use it wity my FitBike Race Magnetic Pro i get the message connected but no signal in Zwift. When i do receive a signal there is nothing reported in Zwift. Also with RGT i get standard 400watt and 240 cadance when i do nothing ;-) Which Arduino version and libaries are you using?


C:\Users\Stephan\Downloads\ArduinoBLE-Cycle-Power-Service-master\ArduinoBLE-Cycle-Power-Service-master\blecyclepower\blecyclepower.ino: In function 'void loop()':
C:\Users\Stephan\Downloads\ArduinoBLE-Cycle-Power-Service-master\ArduinoBLE-Cycle-Power-Service-master\blecyclepower\blecyclepower.ino:134:56: warning: '~' on an expression of type bool [-Wbool-operation]
         if((tm1 < (curr_max - curr_min)) && point && (~is_static))
                                                        ^~~~~~~~~
C:\Users\Stephan\Downloads\ArduinoBLE-Cycle-Power-Service-master\ArduinoBLE-Cycle-Power-Service-master\blecyclepower\blecyclepower.ino:134:56: note: did you mean to use logical not ('!')?
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\HCI.cpp: In member function 'virtual int HCIClass::sendAclPkt(uint16_t, uint8_t, uint8_t, void*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\HCI.cpp:430:41: warning: variable length array 'txBuffer' is used [-Wvla]
   uint8_t txBuffer[sizeof(aclHdr) + plen];
                                         ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\HCI.cpp: In member function 'virtual int HCIClass::sendCommand(uint16_t, uint8_t, void*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\HCI.cpp:472:41: warning: variable length array 'txBuffer' is used [-Wvla]
   uint8_t txBuffer[sizeof(pktHdr) + plen];
                                         ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual bool ATTClass::handleNotify(uint16_t, const uint8_t*, int)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:522:39: warning: variable length array 'notification' is used [-Wvla]
     uint8_t notification[_peers[i].mtu];
                                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual bool ATTClass::handleInd(uint16_t, const uint8_t*, int)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:552:37: warning: variable length array 'indication' is used [-Wvla]
     uint8_t indication[_peers[i].mtu];
                                     ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::findInfoReq(uint16_t, uint16_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:675:23: warning: variable length array 'response' is used [-Wvla]
   uint8_t response[mtu];
                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::findByTypeReq(uint16_t, uint16_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:767:23: warning: variable length array 'response' is used [-Wvla]
   uint8_t response[mtu];
                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::readByGroupReq(uint16_t, uint16_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:817:23: warning: variable length array 'response' is used [-Wvla]
   uint8_t response[mtu];
                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::readOrReadBlobReq(uint16_t, uint16_t, uint8_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:919:23: warning: variable length array 'response' is used [-Wvla]
   uint8_t response[mtu];
                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::readByTypeReq(uint16_t, uint16_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1024:23: warning: variable length array 'response' is used [-Wvla]
   uint8_t response[mtu];
                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::writeReqOrCmd(uint16_t, uint16_t, uint8_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1224:25: warning: variable length array 'response' is used [-Wvla]
     uint8_t response[mtu];
                         ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::prepWriteReq(uint16_t, uint16_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1310:23: warning: variable length array 'response' is used [-Wvla]
   uint8_t response[mtu];
                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual void ATTClass::execWriteReq(uint16_t, uint16_t, uint8_t, uint8_t*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1343:23: warning: variable length array 'response' is used [-Wvla]
   uint8_t response[mtu];
                       ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual bool ATTClass::exchangeMtu(uint16_t)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1425:33: warning: variable length array 'responseBuffer' is used [-Wvla]
   uint8_t responseBuffer[_maxMtu];
                                 ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual bool ATTClass::discoverServices(uint16_t, BLERemoteDevice*, const char*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1439:33: warning: variable length array 'responseBuffer' is used [-Wvla]
   uint8_t responseBuffer[_maxMtu];
                                 ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual bool ATTClass::discoverCharacteristics(uint16_t, BLERemoteDevice*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1495:33: warning: variable length array 'responseBuffer' is used [-Wvla]
   uint8_t responseBuffer[_maxMtu];
                                 ^
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp: In member function 'virtual bool ATTClass::discoverDescriptors(uint16_t, BLERemoteDevice*)':
C:\Users\Stephan\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp:1552:33: warning: variable length array 'responseBuffer' is used [-Wvla]
   uint8_t responseBuffer[_maxMtu];
                                 ^
In file included from C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\variants\ARDUINO_NANO33BLE/pins_arduino.h:3:0,
                 from C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\cores\arduino/Arduino.h:86,
                 from C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\libraries\PDM\src\PDM.h:22,
                 from C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\libraries\PDM\src\PDM.cpp:23:
C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\libraries\PDM\src\PDM.cpp: In member function 'int PDMClass::begin(int, long int)':
C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\cores\arduino/macros.h:28:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define digitalPinToPinName(P)      (P >= PINS_COUNT ? NC : g_APinDescription[P].name)
C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\libraries\PDM\src\PDM.cpp:91:24: note: in expansion of macro 'digitalPinToPinName'
   nrf_pdm_psel_connect(digitalPinToPinName(_clkPin), digitalPinToPinName(_dinPin));
                        ^~~~~~~~~~~~~~~~~~~
C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\cores\arduino/macros.h:28:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define digitalPinToPinName(P)      (P >= PINS_COUNT ? NC : g_APinDescription[P].name)
C:\Users\Stephan\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.6\libraries\PDM\src\PDM.cpp:91:54: note: in expansion of macro 'digitalPinToPinName'
   nrf_pdm_psel_connect(digitalPinToPinName(_clkPin), digitalPinToPinName(_dinPin));
                                                      ^~~~~~~~~~~~~~~~~~~
Tschucker commented 2 years ago

I was able to use Zwift on an iOS device and you may need to start peddling for it to show up. I am currently away from my computer but will check the libraries when possible.

Stephan296 commented 2 years ago

Unfortunately peddling doesn't change anything. But the most strange thing is the error logging when compiling. And with the app RGT it shows without any peddling 400 watt and 240 rpm.

Tschucker commented 2 years ago

Arduino MBed OS board package version 1.1.6 ArduinoBLE version 1.1.3 Nano33BLESensor version 1.0.1

I would also make sure the sensor placement is optimal by using your phone and a magnetometer app to get something similar to what is shown on the blog post. You may need to tweak the power algorithm if the magnetic waveform is significantly different. I used one of the magnetometer examples to output test files in the algorithm design section of the repo and could help if you forked the repo and added similar test sets.

Stephan296 commented 2 years ago

Thx for your support! I forked your repo to: https://github.com/Stephan296/ArduinoBLE-Cycle-Power-Service I have just uploaded some data wtihin a range of 50 a 70 rpm with no resistance.

Tschucker commented 2 years ago

I ran a quick test with my MATLAB algorithm and it looks like you did not set your magnetic calibration value in the Arduino code. and based on your data I would change it from 100 to 400 and switch to using the Y channel of the magnetometer. You then may need to change the calibration once you add various resistance levels, but that should be the absolute value of the maximum magnetic value the sensor sees. blecyclepower.txt

Stephan296 commented 2 years ago

I have got the same result, without any peddling he shows 400watt en 240 rpm... In Zwift and RGT. I dont understand what the problem is. Without any movement/peddling it has to be zero... Also the same error in the log when i compile your ino file as above.

Tschucker commented 2 years ago

try installing these versions of the sensor libraries that I used Arduino_APDS9960 ver. 1.0.3 Arduino_HTS221 ver. 1.0.0 Arduino_LPS22HB ver. 1.0.0 Arduino_LSM9DS1 ver. 1.1.0

and try changing this line "if((tm1 < (curr_max - curr_min)) && point && (~is_static))" to this "if((tm1 < (curr_max - curr_min)) && point && (!is_static))"

this should clear up the errors you are seeing but the algorithm is very much just a proof of concept and was not really meant to work for every bike since I only have one to test on. I have seen on my bike that you may need to peddle a bit to get the algorithm to initialize the max an mins, and since there is no real force sensor power is a bit subjective. So try playing with the "//Configurable values" section of the .ino other than that you may need to start modifying the alg more to fit how the magnetics in the flywheel is configured. Try using a phone app to get some data on how the fields change as the wheel rotates.

wajo666 commented 2 years ago

Hi, I have had same issue. I took data for t1-t8 but how can I create new t_calib_file for my tension?

Tschucker commented 2 years ago

Just enable the different tensions one at a time and use the magnetometer example mentioned in my blog post to measure the different levels. you can then use the mag_serial_to_csv.py program to capture the data. then try playing with the mag_power_calib in the .ino to see if you can dial in the output. The t1-t8 just gives you information on how to design the algorithm the same thing for t_calib and does not directly influence the .ino file. the CSVs are used in the Matlab file to prototype an algorithm that I then used to implement an Arduino program.

wajo666 commented 2 years ago

Ok . I caught t1_calib. But when I changed mag_power to 30. I saw some better output, but can you explain this constant?

mag_samps_per_sec = 16; mag_power_calib = 100; cap_power = 400; decay_factor = 0.5; noise_factor = 3;

How do I know what is better x,y,z from data? Because after change mag_power_calib to 30 but cadence was 250. Maybe I make something bad.

Thank you