ElectricMotorcycleForum.com

Makes And Models => Zero Motorcycles Forum | 2013+ => Topic started by: Gary on February 28, 2021, 11:12:02 PM

Title: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on February 28, 2021, 11:12:02 PM
Hi All,

Has anyone an experience of talking to the SR/F BMS?

We have wired up a USB to TTL lead to an ODB2 plug on pins #9 (Tx), #8 (Rx) and #5 (Signal Earth).  The laptop is running PuTTY.  When connected to the SR/F and turning on the ignition, we do not get a 'prompt' followed by ZERO MBB.  What we get (immediately) is a stream of "DEBUG" statemenr:

DEBUG:   02/26/2021 11:30:31.465  ..\src\Application\zero_mbb_manage_bike.c       : line   521 - Key Sw = OFF
DEBUG:   02/26/2021 11:30:31.519  ..\src\Application\zero_mbb_manage_bike.c       : line   853 - Control flags changed. Old: 0x4036 New: 0x4038
         02/26/2021 11:30:31.521 - State change from STOP to HIB
      
ending with:
      
DEBUG:   02/26/2021 11:32:27.584  ..\src\Application\zero_mbb_manage_bike.c       : line   853 - Control flags changed. Old: 0x0038 New: 0x0030

Wven when the debug stream ends we still do not get a prompt, so we can't talk to the BMS to request data.

Has the BMS got stuck/set in debug mode?

Regards

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Hans2183 on March 01, 2021, 04:22:14 PM
If you send the "help" command it will respond with all the options. I've been using Arduino IDE as a Serial Monitor. The bike doesn't have to be keyed on. If you key it ON you get those reports indeed. Those are normal.

Did you try sending commands? How so? On my original attempts I had the same issue where I could get read the messages but wasn't able to send any valid commands. Was fixed once I started using Arduino IDE so I didn't check what was the original problem.

https://youtu.be/IMt3hgZ8b-0
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 01, 2021, 04:43:33 PM
Hi Hans2183,

I have been plugging my USB/TTL/ODB2 lead into the bike and laptop, running up PuTTY and keying on the bike.  The connection parameters are 115200,8,n,1,N.

The debug messages start immediately and when they finish, the square cursor returns to the left of the screen but the 'prompt' does not appear and the BMS ignores any keyboard commands so I cannot display the help screen.

I did not think to try the serial connection before keying on the bike.  I'll go and try it now.

Thanks Hans

Regards

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 01, 2021, 05:46:50 PM
Hi Hans,

No, I still cannot get the bike to respond to keyboard commands.

I forgot to mention previously that the DEBUG code I listed has been cleaned up.  When it appeared in the PuTTY screen, it did not obey any CR/LF commands.  The code was all over the page.  I had to correct the layout to display the code nicely.

Some years ago I did use the Arduino IDE and a UNO board with some simple sketches just for interest.

Do you use a UNO board as the USB to TTL converter (using pins Tx and Rx) connected to the ODB2 plug?

I have looked at several serial sketches.  Will a simple serial sketch work or is there something specific needed to communicate with the bike?

Regards

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: ms_smart on March 01, 2021, 09:21:52 PM
Hi Gary, are you running Windows? You may want to test Coolterm. Attached my config file. Obviously you need to change the com port. You need to type in Enter (or help + Enter as suggested by Hans) to get the prompt.

I am using a FT232RL based TTL to USB converter. I think I have the same one Hans is using in his video. I also tested a cheap fixed cable like this one: https://de.aliexpress.com/item/1005001587731393.html that can be soldered directly to a OBD2 socket, but you may get problems with the windows driver since the pl2303 chip is not genuine.

I also get sometimes debug messages, but not always. You can ignore them. Just type your command.

Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Hans2183 on March 01, 2021, 10:13:07 PM
Indeed is a cheap FT232RL chipset that I use, no arduino. Those are used to program arduino's that don't have this built in hence my original idea to test it with the Arduino IDE. You just need the serial monitor part of the IDE. That will likely resolve your issue. Coolterm might also work. I didn't try that.
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 01, 2021, 10:18:05 PM
Hi ms_smart,

I'm running Linux Mint 19.3 (Tricia) on a nice, small netbook with the PuTTY programme.  My USB to TTL lead is also an FTDI IC device 'FT232RL'.  The problem I have is that the bike is talking to the laptop but not listening to the keyboard.  Han2183 mentioned a similar problem that he solved by using the Arduino IDE software.

Actually, I do have a windows based laptop.  It is a bit large and clunky but I will try using that with coolterm to see if that is a solution also.

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 01, 2021, 10:24:49 PM
Hi Hans,

OK, I get it.  Just plug the lead into the laptop and bike and select 'Serial Monitor' from The Arduino IDE's 'Tools' menu choice.

How do you set the connection parameters: 115200,8,n,1,N?

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 02, 2021, 12:23:32 AM
Hi Hans,

Found it. 

void setup()
{
  Serial.begin(115200);
}

void loop() {}

yes?

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Hans2183 on March 02, 2021, 02:01:26 AM
no you don't need to add any code in the sketch (unless you have an arduino that you want to program to listen on that port). When opening the serial monitor at the bottom there are some options for baud rate. For the device selection you have to pick the right one from the arduino IDE menu Tools > Port.
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 02, 2021, 05:18:31 AM
Hi Hans,

Thank you for clarifying that.  I'll try the IDE to connect to the bike.

Regards

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Auriga on March 02, 2021, 08:35:19 AM
Hi Hans,

No, I still cannot get the bike to respond to keyboard commands.

I forgot to mention previously that the DEBUG code I listed has been cleaned up.  When it appeared in the PuTTY screen, it did not obey any CR/LF commands.  The code was all over the page.  I had to correct the layout to display the code nicely.

Some years ago I did use the Arduino IDE and a UNO board with some simple sketches just for interest.

Do you use a UNO board as the USB to TTL converter (using pins Tx and Rx) connected to the ODB2 plug?

I have looked at several serial sketches.  Will a simple serial sketch work or is there something specific needed to communicate with the bike?

Regards

Gary

Are you sending a carriage return + line feed on your serial messages? You have to on FST. Sometimes noted as /r/n.
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 02, 2021, 03:34:28 PM
Hi Auriga,

That is a good point.  I'll check that.

Thanks

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: jjfinn on March 02, 2021, 06:30:05 PM
The problem is Putty cannot send  \r\n when you press Enter. Zero wants to have \r\n after each command to react. You need to do it manually after each command on the MBB console. E.g. "help" + Crtl-M + Ctrl-J. Here's the article: https://z49x2vmq.github.io/2017/11/12/putty-cr-lf-en/
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 02, 2021, 06:36:37 PM
Hi jjfinn,

Brilliant.  Well done on finding that.  I'll try that on the bike tonight.

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: ninja62 on March 02, 2021, 07:44:06 PM
The problem is Putty cannot send  \r\n when you press Enter. Zero wants to have \r\n after each command to react. You need to do it manually after each command on the MBB console. E.g. "help" + Crtl-M + Ctrl-J. Here's the article: https://z49x2vmq.github.io/2017/11/12/putty-cr-lf-en/ (https://z49x2vmq.github.io/2017/11/12/putty-cr-lf-en/)


You can configure putty to send CR+LF automatically in the configuration window, Terminal section. Just tick both 'Implicit CR in every LF' and 'Implicit LF in every CF'. ;)
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 05, 2021, 10:04:38 PM
Hi All,

Using PuTTY and Mttty I can connect to the SR/F (at last!).  Herewith the process and the results I achieved:

1.  DO NOT key on the bike
2.  Plugin the USB connector into the laptop
3.  Plugin the OBDII connector into the SR/F
4.  Run up PuTTY
5.  Set 115200,8,n,1,N and hit connect

The cursor will just sit at the left hand edge of the PuTTY window
6.  Now enter Ctrl + m
7.  Now enter Ctrl + j

The SR/F will wake up and reply:
ZERO MBB>

8.  Type in 'help' (without the ' symbols)
9.  Now enter Ctrl + m
10. Now enter Ctrl + j

The SR/F will reply:
ZERO MBB> help

*************************************************************
                                                             *                 Main Menu                           *
                                    *************************************************************

                   help            - Display this Help screen
                                                               login           - Display login level, or login

                                -- MBB Operational Information --
                                                                   version         - Board and firmware revision
                                  dash version    - Dash and Telit firmware revision
      time            - Current time
                                      in              - State of all inputs
                                                                             faults          - Active faults (-v for verbose)
                                               notif           - Active notifications
       stats           - All statistics


=====================================================================

As you can see, the information is there, it is just difficult to read.  The SR/F does not appear to send CR/LF's

Cleaning up the poor formatting give this:


*************************************************************
*                 Main Menu                           *
*************************************************************

help            - Display this Help screen
login           - Display login level, or login

-- MBB Operational Information --
version         - Board and firmware revision
dash version    - Dash and Telit firmware revision
time            - Current time
in              - State of all inputs
faults          - Active faults (-v for verbose)
notif           - Active notifications
stats           - All statistics

Any ideas on how to fix this?

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 05, 2021, 10:58:47 PM
Hi Ninja62,

The penny has just dropped.  I only selected 'Implicit LF in every CF'.  I forgot the 'Implicit CR in every LF'.  OK, back out to the bike now.

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: karlh on March 07, 2021, 11:28:42 PM
Hi Hans,

OK, I get it.  Just plug the lead into the laptop and bike and select 'Serial Monitor' from The Arduino IDE's 'Tools' menu choice.

How do you set the connection parameters: 115200,8,n,1,N?

Gary

Gary,

I understand your connection parameters except for the final N.  What does that represent?
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 09, 2021, 11:28:59 PM
Hi Karlh,

The final 'N' refers to the flow control, so set this to 'None'.

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: karlh on March 09, 2021, 11:45:17 PM
Thanks.  You don't often see that listed with the other parameters.
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 23, 2021, 06:32:08 PM
Hi All,

Results of access tests via a Linux laptop

==================================

LINUX MINT 19.3 (TRICIA)
 
PUTTY - Set up the configuration as follows:

Category: Terminal
- tick 'implicit CR in every LF'
- tick 'implicit LF in every CR'

NOTE:  This ensures that the returned text is correctly formatted.

Category: Connection/Serial
- Serial Line to connect to: /dev/ttyUSB0
- Speed: 115200
- Data: 8
- Stop: 1
- Parity: None
- Flow Control: None
 
Click on 'Category: Session'
Click on 'Serial', a radio button
In 'Saved Sessions' click on 'Default Settings'.
Click on 'Save'

 PUTTY METHOD#1
Open:  a Terminal window
Type:  'sudo chmod -R 777 /dev/ttyUSB0'
Enter: [password]
Type:  'sudo putty'
Select 'Open'
Enter: 'CTRL + m' then 'CTRL + j' to wake up the Zero MBB and display the '>'.
After each entry, ie, 'help', finish with 'CTRL + m' then 'CTRL + j' to make the MBB respond.

 PUTTY METHOD#2 - I forgot to try this one!
By default, PuTTY sends the Telnet New Line code when you press Return, instead of sending Control-M as it does in most other protocols. 
PuTTY emulates xterm which emulates vt100. To have putty send CR/LF when pressing enter, type ESC[20h in putty after connecting to the serial device. This sets VT100 LNM true.
 
 PUTTY METHOD#3
Sending CR+LF is possible in modified PuTTY. Source code is available at https://github.com/gniemirowski/putty-crlf and Windows binary at https://www.grzegorz.net/pliki/putty-crlf.zip When you run this version just go to Terminal -> Keyboard and select "CR LF" for "The Enter key" option.
 
===========================================
'CTRL + m'   CR  13 or 0D
'CTRL + j'  LF  10 or 0A
===========================================
COOLTERM

http://freeware.the-meiers.org/CoolTermLinux32Bit.zip

Open:  a Terminal window
Type:  'sudo chmod -R 777 /dev/ttyUSB0'
Enter: [password]
Run CoolTerm
- Speed: 115200
- Data: 8
- Stop: 1
- Parity: None
- Flow Control: None
Select Connect

===========================================
INSTALL PUTTY CR-LF

1.  Delete all the putty files from any previous install attempts on the laptop, if exist.
2.  sudo apt-get install build-essential libgtk-3-dev
3.  git clone https://github.com/gniemirowski/putty-crlf
cd putty-crlf
./mkauto.sh
./configure --disable-git-commit
make
4.  Run new putty-crlf:
cd putty-crlf
./putty

===========================================
CREATE BASH SCRIPT - serial.sh

path to serial.sh: /home/username/

touch /path/to/serial.sh
chmod a+x /path/to/script.sh
'mcedit /path/to/script.sh' and paste this code:

#!/bin/sh
echo logan | sudo -S chmod -R 777 /dev/ttyUSB0
/path/to/putty-crlf/putty

==========================================
TERMINAL
/home/username/serial.sh

LAUNCHER
/home/username/serial.sh
==========================================

I hope the above is of use to you.  Whatever method I use, I always have to enter ctrl+m and ctrl+j after each command to get the MBB to respond.  I don't know why.  I maybe a Linux thing.  I'm going to try the above using a windows 10 laptop.  I'll let you know how I get on.  Thanks to all of you for your help on this forum.

Cheers

Gary
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Auriga on March 24, 2021, 02:15:13 AM
I've always preferred screen or minicom over putty on linux. Zero itself seems to primarily use Teraterm on windows, and that's what they have us use as well.
Title: Re: SR/F Serial/ODB2 connection to the BMS
Post by: Gary on March 24, 2021, 05:08:34 PM
Hi Auriga,

Thanks for the info.  I'll try those products

Cheers

Gary