Pages: [1] 2   Go Down
Author Topic: SparkFun CAN Bus Shield  (Read 4095 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I bought the device mentioned and I'm having difficulty getting it to work. I've got the DB9 to OBDII cable and I'm testing with a 2008 Subaru Legacy.

I'm using the manufacturer's Demo code (see attached) with a few modifications; since I'm not using the LCD screen, I have modified the lines in the Loop() to say "Serial.println" instead of "sLCD.print" so that I can see the values.

What happens is this- I see the intro line, which says "ECU Reader"; I then see 4 lines which instruct you on which button to hit. When I hit "Down", I see "CAN", then "CAN Init OK", and then I will see anywhere from 1 to 6 lines containing the actual values before the stream simply locks up and doesn't print anything else. The values are accurate because I'm watching the gauge cluster as I run it.

I have tried changing the Serial baud rate to 115200, increasing "buffer[]" to 1024 bits (code won't run), taking a random crack at changing the CAN bus speed to 1Mbps (Legacy is on 500Kbps, so this also didn't work), changing the Loop() delay to both 10 msec and 1 sec, and finally commenting out any operation besides printing the CAN bus values to the screen. Nothing seems to change my initial issue.

Anyone have any ideas?

* ecu_reader_logger.ino (15.59 KB - downloaded 49 times.)
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 There is a lot of code to look at and I am only a Novice anyway. I will take a wild stab at it and say that you need to try taking out the GPS part of the code, and delays and see if that helps. I think maybe that you are getting over ran by the GPS serial.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll try this when I can (should be Friday).

I don't know, though, because if I hit "DOWN" the loop should only call the polling requests and send to Serial, not run any of the other functionality (i.e. GPS, logging, SD Card test).
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  Your code is around 600 lines and is a bit hard to find an obvious problem. I have been working on an OBD2 style code myself and like your code it is getting bigger and bigger with every addition of a new function.

 What has worked the best for me is working out one piece at a time. For instance start with the CAN communication, capture the data that is returned from your car and print it to the serial monitor. When you see that you data looks reliable and correct set that code aside. Next, start the logging portion of the code by storing your time stamp or whatever your first saved line that you want to have on your card. When you are ready get the GPS to work by itself. etc.

 When each part of the code is functional and reliable, add one more piece and test your new code to make sure it still works.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's the thing, though- I'm only testing what's in the Loop() method right now. The Setup() method determines whether or not the other functions will be called depending on which button is pressed, and I'm only pressing "Down".

The issue here is that the Loop() method only runs a handful of times and then locks up, and the Reset button must be hit to bring it back online. The problem here is whatever is happening in those 30 or so lines of code in the Loop() method.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you (or does anyone reading this) know of a good way to track the buffers in the above code to see if I am indeed running into a buffer issue?

Or is there a Debugging step I'm missing here to try and identify the issue?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Arduino are you using? If it is a 328-based Arduino, it has 2048 bytes of SRAM.

Code:
#include <SD.h>        /* Library from Adafruit.com */
There goes 512 bytes or more.

Code:
char buffer[512];  //Data will be temporarily stored to this buffer before being written to the file
char tempbuf[15];
char lat_str[14];
char lon_str[14];
Another 555 bytes gone.

With all the Serial.print() statements, and serial buffers, etc., you are are almost certainly running out of memory. There are a couple of available memory functions that you can add to the sketch, and call at appropriate points, to determine whether or not you really are out of memory.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wanted to ask something for some time now...
Can someone, with that shield and that cable, not only read from the brain of the car, but also program and change settings to the brain of the car?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul- good call on that, I'll check the version when I get home. If I find that's the case, what are the memory functions you mentioned? And what would be a more appropriate way to see what the device is doing live than a bunch of Serial.Print() statements?

Nik- the answer is sometimes, maybe. I say that because the CAN standard really only defines bus communication, not how the vehicle's ECU responds to requests or how they store information. Sometimes even figuring out the correct polling responses is different car-to-car, and then there is the question of whether the OEM allows for map or table changes on the bus. Sometimes, you have to directly connect to the EEPROM in the car.

The ECU may not provide the level of functionality you're looking for, either. This is why racers and tuners use replacement ECUs. If you're serious about going that route, Motec makes an ECU called the M1 in which you actually write a good portion of the firmware yourself, in a C-based language.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Memory checking links of interest:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274126895
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1224680656
http://www.arduino.cc/playground/Code/AvailableMemory

Quote
And what would be a more appropriate way to see what the device is doing live than a bunch of Serial.Print() statements?
None, really, but you can move the constant strings out of SRAM, using the F() macro.
Serial.print(F("This string doesn't occupy any SRAM"));
Serial.print("This one does");
Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wanted to ask something for some time now...
Can someone, with that shield and that cable, not only read from the brain of the car, but also program and change settings to the brain of the car?

If it's possible I fairly sure you don't want to be playing around with this ability, at least not with any automobile you plan on keeping reasonably functional.  Also, a major mistake could "brick" one or more of the automobile's microcontrollers, which for most people would mean an expensive trip to a dealership/professional mechanic familar with automotive electronics systems for repairs.  In other words, don't try this at home unless you actually know what you're doing!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul, I'll dig into all that tonight.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, a few things-

The board I'm using is the Arduino Uno, which uses the ATMega328. Therefore, I am dealing with that 2KB of SRAM.

When I use the F() macro like so...
Code:
Serial.print(F(buffer));
...I get an error that reads...
Code:
error: initializer fails to determine size of '__c'
I'm looking around on the Net for solutions now.
Logged

Amsterdam, The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Living with the internet of things
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not familiar with the issue. Maybe using another library can solve the issue: http://arduiniana.org/libraries/flash/
Logged

Kind regards,

Mike

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I noticed on another forum someone mentioning that they included a terminating resistor on the shield side of the CAN bus; anyone think that might also be a problem?
Logged

Pages: [1] 2   Go Up
Jump to: