Coder Social home page Coder Social logo

sparkfun_can-bus_arduino_library's Introduction

SparkFun CAN-Bus Arduino Library

SparkFun CAN-Bus Shield

SparkFun CAN-Bus Shield (DEV-13262)

Arduino library for using all features of the CAN-Bus Shield.

Repository Contents

  • /examples - Example sketches for the library (.ino). Run these from the Arduino IDE.
  • /extras - Additional documentation for the user. These files are ignored by the IDE.
  • /src - Source files for the library (.cpp, .h).
  • keywords.txt - Keywords from this library that will be highlighted in the Arduino IDE.
  • library.properties - General library properties for the Arduino package manager.

Documentation

Products that use this Library

License Information

This product is open source!

Please review the LICENSE.md file for license information.

If you have any questions or concerns on licensing, please contact [email protected].

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

sparkfun_can-bus_arduino_library's People

Contributors

cmfrancis avatar ivankravets avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparkfun_can-bus_arduino_library's Issues

Add voltage and version ELM calls to the lib

This lib works fine for PID codes. But there are useful bits of info (voltage, version) that don't use PID codes, they use ELM327 commands. In another Arduino OBD library, I found the relevant calls (below). Can they be adapted and merged into the lib? I don't think I can adapt them myself.

float COBD::getVoltage()
{
    char buf[32];
	if (sendCommand("ATRV\r", buf, sizeof(buf)) > 0) {
		char* p = getResultValue(buf);
		if (p) return (float)atof(p);
    }
    return 0;
}

byte COBD::getVersion()
{
	byte version = 0;
	for (byte n = 0; n < 3; n++) {
		char buffer[32];
		if (sendCommand("ATI\r", buffer, sizeof(buffer), 200)) {
			char *p = strchr(buffer, ' ');
			if (p) {
				p += 2;
				version = (*p - '0') * 10 + (*(p + 2) - '0');
				break;
			}
		}
	}
	return version;
}

add support for 1 mbps baud rate

I have the Sparkfun can bus shield and I'm tryng to connect to an ecu that works at 1 mbps. Unfortunately this library only supports baud rates up to 500 kbps. I'm sure that is easy to edit the library but I don't know how to do this.
Can you please have a look at this?

thank's
Davide

Does this library support CAN protocol Flow Control?

Does this library support CAN protocol Flow Control?

In message definition tCAN, I cannot find flow control byte. I guess this library doesn't flow control, is it? When we receive multi frames, for example, some PID response has multi frames:

7C8 8 10 0A 61 12 01 00 00 07 
7C8 8 21 10 00 80 00 00 00 00 

how to handle this situation?

problem with Sparkfun_Can_Demo

I am working on a project so I bought a sparkfun redboard Plus and a sparkfun can-bus shield. I went to program it with OBD-II to DB9 Cable that I bought from you with the library (CAN-Bus_Shield-master) that you have as an example and at first I used the SparkFun_CAN_Demo library, I ran it with the arduino ide but it not working(can't init can). After various tests I have done, I have come to the conclusion that some library has a problem, but I can't find which library it is or the problem where are finding. The test was done on an audi a4 b6 quattro 2002 1.8T. Maybe have you updated the code and forgot to upload the corrected one?? I believe some library has a problem but I don't know which one is not a topic from the program that has the selection table for rpm or throttle or maf sensor but some library. As I tell I working into an project so any help is good.I am waiting for feedback

Add support for 29 bit identifier

Hi,

I need to have support for 29 bit identifiers in a project I'm working on.

I have working code for it that I would like to contribute, but I'm unsure what the best way of handling the 11 vs 29 bit difference.

I have added a bool for keeping track of if it's a 29 or 11 bit identifier
typedef struct
{
uint32_t id;
struct {
int8_t rtr : 1;
uint8_t length : 4;
} header;
uint8_t data[8];
bool extended;
} tCAN;

I would like to keep all old code working though, and I have two suggestions. Either change the mcp2515.c to .cpp which would allow constructors that set default extended=false or add a new struct for extended messages. Do you have any other suggestion?

How to run at 1Mb/s?

I'm wondering how we can add the 1000kbps setting to the library? I edited Canbus.h to add CANSPEED_1000, however it does not seem to work trying to obtain the rpm from a vehicle. I'm not sure if the numbers 1 3 and 7 are just there to set the "priority" like in networking to set connection priority or if it means something else?

I only have one set of the chips so can't test with a second set to tell if it is in fact initializing the controller at the higher speed or not.

#define CANSPEED_125 7 // CAN speed at 125 kbps
#define CANSPEED_250 3 // CAN speed at 250 kbps
#define CANSPEED_500 1 // CAN speed at 500 kbps
#define CANSPEED_1000 0 // CAN speed at 1000 kbps

No GPS reading on Arduino Uno R3

I was not able to get any GPS readings. I am using:
CAN-BUS Shield (DEV-13262) and GPS Receiver
EM-506 (GPS-12751) ordered bis SK Pang
Arduino Uno R3

Looking at the hookup guide, it actually seems that the author was also not able to get a GPS fix, The author suggested the reason was poor GPS connection, but perhaps it's actually the code. Looking through the code it seems to me that it will not work on Arduino Uno with software serial, because it does too many other things including delays to be able to read the incoming data from the serial GPS module.
https://learn.sparkfun.com/tutorials/can-bus-shield-hookup-guide

Message transmission using CAN transmission buffers

I am trying to load n number of CAN messages(datatype tCAN) to the CAN transmission buffer (load it 3 messages at a time), and send them at a go to the CAN bus. I am not able to figure out the required methods from the sparkfun datasheets and online forums. Can anyone please suggest how to do that or any document for the same ?

115200 baud

Anyone who knows how to implement 115200 baud instead of the standard baud rates?

SAMD M0 Version

I imagine this is highly unlikely, but any chance someone can port this to SAMD architecture? Eg, to be used with an Adafruit M0 device or similar.

Leonardo compatible?

Is the CAN shield supposed to work with the Leonardo? It doesn't work for me, and there are various forum threads that say the SPI pins aren't in the right place.

CAN transmission is working, but not the listening part

We are using Sparkfun CAN shield and Arduino Uno to build a CAN network. We are observing the data in CAN network using KVaser Canking. When we send a data to the CAN bus, we can see the data in KVaser window. But, when we try to read something from the CAN bus, it is showing garbage values. Note that 120 ohm is also there. Here is the code:


`
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

//********************************Setup Loop*********************************//

void setup() {
  Serial.begin(115200);
  Serial.println("CAN Write - Testing transmission of CAN Bus messages");
  delay(1000);
  
  if(Canbus.init(CANSPEED_250))  //Initialise MCP2515 CAN controller at the specified speed
    Serial.println("CAN Init ok");
  else
    Serial.println("Can't init CAN");
    
  delay(1000);
}
  
unsigned long now=0, prev=0; 
 
void loop() {
  mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
  tCAN message;  // message read from the bus
  tCAN amessage;

  // Attack message details
  amessage.id = 0x631; //formatted in HEX
  amessage.header.rtr = 0;
  amessage.header.length = 8; //formatted in DEC
  amessage.data[0] = 0x00;
  amessage.data[1] = 0x00;
  amessage.data[2] = 0x00;
  amessage.data[3] = 0x00; //formatted in HEX
  amessage.data[4] = 0x00;
  amessage.data[5] = 0x00;
  amessage.data[6] = 0x00;
  amessage.data[7] = 0x00;
  

   while(! mcp2515_check_message()){
    
   }
  
    if(mcp2515_get_message(&message) and message.id==0x630){ //wait for target message on the bus
      amessage.id = 0x630;
      mcp2515_send_message(&amessage);//this is not working
      Serial.println("Sending attack message");//this is not working
   }
  
       auto error_tec = mcp2515_read_register(TEC);
       Serial.print("TEC Count of adversary : "); //this is working
       Serial.println(error_tec);  //this is working
   
       
}

`Can some one help how to resolve this?

lat and lon number are 10 times too large

The lat and lon values returned seems to be 10 times too large.

I am based in Stockholm/Sweden and my correct lat/lon is 59.317 / 18.054.
However using:
f_get_position(&flat, &flon, &fix_age)
I get: 593.17 / flon: 180.54

And using:
get_position(&lat, &lon, &fix_age)
I get: 59317041 / 18054290

I use:
CAN-BUS Shield (DEV-13262) and GPS Receiver
EM-506 (GPS-12751) ordered bis SK Pang
Arduino Uno R3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.