# Can Bus Controller



## frodus (Apr 12, 2008)

It doesn't just need to be CAN Bus, it needs to be able to map CAN messages in a way that the Orion can understand. 

Right now, I know Orion and HPEVS worked together to get the 1238 controllers working with the Orion.... and later Elithion added support.

Talk to Orion and ask them, and maybe shoot Netgain an email.


----------



## Jarrad (Oct 19, 2013)

Yes support from the Orion would be nice but, I really just want the signal to torque and the Arduino with less wiring. 

You're making me think about AC with that Curtus controller but, where do I find a cheap AC motor?

Realistically the Soliton jr is nearly $1000 less than the Netgain. I don't think I need more than 600A with my 7.25" motor and 2300lb mini cooper.


----------



## frodus (Apr 12, 2008)

email me. I sell HPEVS stuff and can do my best to get you a good deal on an AC motor/controller package.


If you wanted to use another CAN controller, you'd need an arduino, a bunch of code to act as a "gateway" from PURE CAN to OBDII CAN messages, and respond to torque correctly over bluetooth. Just connecting an OBDII bluetooth dongle to a PURE CAN on a controller won't work, it must know that it needs to respond to PID requests from Torque. I can share some of the messaging to Torque AT commands, and PID requests. Let me know if you decide to do that (email me) and I can at least get you some of that info.


----------



## Jarrad (Oct 19, 2013)

I don't think I can make that switch right now. I haven't even got this car licensed I need to get it on the road and see what the range is like. I'm starting to think about opening up the Kelly to see if if I can find the problem.


----------



## merciermw (Jan 25, 2015)

frodus said:


> If you wanted to use another CAN controller, you'd need an arduino, a bunch of code to act as a "gateway" from PURE CAN to OBDII CAN messages, and respond to torque correctly over bluetooth.


I have been struggling with this exact issue for a while now and need help! I have the Orion BMS displaying data on Torque with custom PIDs and I have an Arduino with CAN-bus shield collecting sensor data. I want to send the sensor data over CAN / OBDII to Torque and display the data. What is that bunch of code to get from PURE CAN to OBDII CAN??


----------



## CKidder (Dec 12, 2009)

First of all, I need to make sure that you are aware that you don't send data to torque in so much as it actually asks for data and you then reply with that data. The ball is supposed to be in Torque's court. It asks, you send.

There is a bunch of stuff to do to support this - you need to either emulate an ELM327 chip over bluetooth or just directly use canbus on the OBDII wiring. It sounds like you can just directly do canbus to OBDII. Either way the GEVCU project has the code you need. You might check here for code to get you started:

https://github.com/collin80/GEVCU/blob/master/CanPIDListener.cpp


----------



## merciermw (Jan 25, 2015)

Thanks for the explanation of the ask/reply communication with Torque - I was not aware. I was trying to send CAN messages out on the bus with custom PIDs and have Torque pick them up. Now I think I get the logic of what needs to happen:


Torque sends out a request for data from a PID
Microcontroller on CAN-bus (Arduino) listens for the PID request
Arduino replies with data associated with the PID

I have an ELM327 running CAN information from Orion BMS to Torque already so I am taking the approach to go to canbus to OBDII. Now I am digesting the GEVCU code, communication I have sniffed over CAN going to Torque from the BMS and discussion at http://torque-bhp.com/forums/?wpforumaction=viewtopic&t=3824.0. 

I feel closer than I did yesterday...


----------



## frodus (Apr 12, 2008)

Look at these PIDs
http://en.wikipedia.org/wiki/OBD-II_PIDs

basically, if torque sends 01 0C, you reply with Engine RPM. 01 0D is Vehicle speed. 

Torque also allows you to do custom PIDs that you define.


----------



## merciermw (Jan 25, 2015)

Break Through!!

After discovering this thread: http://torque-bhp.com/forums/?wpforumaction=viewtopic&t=4852.0, and tracking down the library "moreause" was using: https://code.google.com/p/mechanic/, and playing with the code, I can now send my own custom PID sensor data from Arduino into the Torque Pro app!! 

Notes about my setup:

Orion BMS Jr acts as ECU
OBDLink (ELM327) communicates over bluetooth to Torque
Ardunio Mega with CAN-Bus shield has code shown below
Dummy sensor values sent over PID 0x90 and 0x99
Here you can see the values reaching Torque









From there I started to send actual sensor data. I started with a thermocouple temperature signal and found the limitation of this CAN-bus code...it takes a lot of processing because of all the data flying back and forth. The thermocouple reading has its on processing going on to amplify the voltage signal and process it over the ADC on the Arduino. With all that going on the temperature signal is only sent once before the Arduino freezes and hangs up. I have tried both 250kbps and 500kbps baud rate with the same issue.

So, next stage will be to take all of my sensor data into on arduino, send it over CAN-bus with the simple library method (no need to wait for messages, just constantly send), pick up these messages with the Arduino running the Mechanic code and then send the CAN-messages out to Torque.

Sound like a good plan?

Here is the working code

```
/*
*********************************************************************
* Mechanic – Hacking your car
*
* Copyright (C) 2013 Joerg Pleumann
*
* This example is free software; you can redistribute it and/or
* modify it under the terms of the Creative Commons Zero License,
* version 1.0, as published by the Creative Commons Organisation.
* This effectively puts the file into the public domain.
*
* This example is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LICENSE file for more details.
*/
#include <Mechanic.h>

ObdInterface obd;
ObdMessage out;
ObdMessage in;
int SensorValue = 0;
float PsiValue = 0;
float Temp;
int ValuePID90xA;
int ValuePID90xB;
int ValuePID99xA;

void setup() {
Serial.begin(115200);
//while (!Serial);
Serial.println();
Serial.println();
Serial.println("ADDR LN MO PI D0 D1 D2 D3 D4");
Serial.println("——– — – — – — – — –");
obd.setSlow(false); //This is where you can change to 250kBps by calling true
obd.setExtended(false);
obd.setDebug(false); //When true, all incoming and outgoing are printed on the Serial console
obd.setNoFilter(true); // Show all messages, not just ECU answers - this has to be true for my setup to work
obd.begin();
out.address = 0x7eF; // Address of the ECU (Arduino)
out.mode = 0x41; //Using mode 1 "show current data" response is plus 40
}
void loop() 
{
if (obd.receiveMessage(in)) 
{
Serial.println(in);
if (in.pid == 0x90) { // Si pid est 90 envoie la valeur courante....The PID request sent from main ECU (Torque)
out.address = 0x7eF;
out.length = 0x4; //4 bytes includes the address and mode bytes
out.pid = 0x90;
out.values[0] = ValuePID90xA;
out.values[1] = ValuePID90xB;
obd.sendMessage(out);
Serial.println("sending");
Serial.print(" PID 0x90,Sensor ");Serial.print(SensorValue);
Serial.print(" Psi: "); Serial.print(PsiValue);
Serial.print(" A: "); Serial.print(ValuePID90xA);
Serial.print(" B: "); Serial.println(ValuePID90xB);

}
if (in.pid == 0x99) { // Custom PID is 0x99 for next sensor set
Serial.println("sending");
Serial.print(" PID 0x99,Sensor ");Serial.print(SensorValue);
Serial.print(" A: "); Serial.println(ValuePID99xA);
out.address = 0x7eF;
out.length = 0x4;
out.pid = 0x99;
out.values[0] = ValuePID99xA;
out.values[1] = 0;
obd.sendMessage(out);
}
}
// Valeur pour PID 0x90
//SensorValue = analogRead(A0) + 1;
SensorValue = 200; //used fixed value for A0 for verification
PsiValue = (45.6125*SensorValue/1024) + 0.148721; // at fixed value of 300, result is 13.51
ValuePID90xA = (int) PsiValue; //result should be 14
Temp = (PsiValue - ValuePID90xA) * 100; //14-13.51 = .49 * 100 = 49
ValuePID90xB = (int) Temp; // = 49
//Torque equation: (A*100+B)/100-([33]*0.14503)
//= (1449)/100-(4.78599)
//= 14.49-4.78599
//= 9.704 Psi
//Min = -15.0 Max = 30.0
/*
Serial.print(” PID 0×90,Sensor “);Serial.print(SensorValue);
Serial.print(” Psi: “); Serial.print(PsiValue);
Serial.print(” A: “); Serial.print(ValuePID90xA);
Serial.print(” B: “); Serial.println(ValuePID90xB);
*/
// Valeur pour PID 0x99
ValuePID99xA = map(SensorValue,0,1024,0,256); // 5 Volts ou 1024 = 45.6125 Psi et modifier en 0 a 255 et envoye comme pid de short trim bank 2
//obd.setNoFilter(false); // Show all messages, not just ECU answers
//delay(250);
//obd.setNoFilter(true);
}
```


----------



## 2pro4you2009 (Sep 29, 2015)

Hi,
Does this do the same from EVTV?

http://store.evtv.me/proddetail.php?prod=ArduinoDueCANBUS&cat=28
and does this kit do the same as Merciermw has build? Any experiences? I think Bluethoot is missing from EVTV kit. I am beginner with Arduino .

I am planning my new project, to convert BMW 320 Sedan to EV. Most parts I have but CAN BUS would be nice to add for chagers etc or even ChaDemo chargeing .


----------



## mna (Apr 20, 2016)

@merciermw - great detail in your posts! Although I'm a little confused as to what your goal was. were you trying to simulate data being sent from a BMS to the Torque app using an arduino?


I'm doing my first hack with a vehicle so a lot of this is new to me. I'm trying to figure out if the situations described in this thread pertains to me. I want to send the data my Orion BMS is collecting over bluetooth to a custom app (not the Torque app).


----------

