Seeed can bus shield 2.0

Status
Not open for further replies.

Cypher

New member
Hi all,
I am really new to this board and I am still learning and finding and figuring out the ways this board works, I am somewhat new to arduino as well but I have made a few projects as well but this one has got me I am currently trying to get a seeed CAN-BUS v2.0 shield to work with this board but I cant get the board to pass the "enter setup mode" it fails everytime. I am wondering to start with can someone point me in the right direction on what pins actually need to be connected, I can get this to work on an uno just not this board. I did reroute the sck pin to 14 due to the LED already using this pin. Any advise and or picture/hand holding would be great.

From what I have seen in the pin_arduino.h the pins should be the same as the UNO which make me think I am missing something. Here is a picture below to show what pins I have were.

teensy canbus.PNG

here is my code below

Code:
// You can use any (4 or) 5 pins for OLED screen
#define sclk 2
#define mosi 3
#define dc   4
#define cs   5
#define rst  6

// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <arduino.h>
#include <gfxfont.h>
#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>

// Option 1: use any pins but a little slower
Adafruit_SSD1351 tft = Adafruit_SSD1351(cs, dc, mosi, sclk, rst);

#define COMMAND 0xFE
#define CLEAR   0x01
#define LINE0   0x80
#define LINE1   0xC0
#define COMMAND2 0x7C

//#define DOUBLE_CLICK_DELAY 100

#define NR_OF_CHANNELS (sizeof(channel)/sizeof(data_channel))

/* Define Joystick connection pins */
#define UP     A1
#define DOWN   A3
#define LEFT   A2
#define RIGHT  A5
#define CLICK  A4

//the cs pin of the version after v1.1 is default to D9
//v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
const int LED        = 8;
boolean ledON        = 1;

MCP_CAN CAN (SPI_CS_PIN);           //set CS Pin


enum {
  MIN,
  MAX,
  RUNTIME
};

struct data_channel {
  char *name;
  int multiplier;
  int divisor;
  int offset;
  int min_value;
  int max_value;
  int value;
};

int a,b,c,d,current;

int page_type = RUNTIME;

unsigned int last_click = 0;
int flip_request;

data_channel channel[] = {
// name, multiplier, divider, offset
    { "ECT", 1, 1, -50, 9999 },
    { "AFR", 1,1, 0  , 9999 },
    { "TPS", 1, 1, 0 , 9999 },
    { "MGP", 1, 1, -100, 9999 },
    { "IaT", 1, 1, -50, 9999 },
    { "Ign", 1, 1, 0, 9999 },
    { "Fup", 1, 1, 0, 9999 },
    { "Idc", 1, 1, 0, 9999 },

};

void flip_page () {
  flip_request = 1;
  //delay(250);
  tft.fillScreen(BLACK);
}

void setup() {
  SPI.setSCK(14);
  SPI.setMOSI(11);
  SPI.setMISO(12);
  Serial.begin(115200);
  Serial.println("ECU Reader");  /* For debug use */
  delay(10);
  tft.begin();
  delay(100);
  tft.fillScreen(BLACK);
  Serial.println("initializing can");
  if (CAN_OK != CAN.begin(CAN_500KBPS))              //Init can bus : Baudrate = CAN_500KBPS, Swapped for mcp_can begin

 {
    tft.setTextSize(1);
    tft.setTextColor(GREEN);
    tft.print("Can Init Screwed");     //Swapped for TFT
    delay(2000);
    tft.fillScreen(BLACK);
  }/*
  tft.setTextSize(2);
  tft.setTextColor(GREEN);
  tft.print("Can init ok");
  delay(1000);
  tft.fillScreen(BLACK);     //swapped for TFT 
  current = 0;
*/
    //Initialize analog pins as inputs
  pinMode(UP,INPUT);
  pinMode(DOWN,INPUT);
  pinMode(LEFT,INPUT);
  pinMode(RIGHT,INPUT);
  pinMode(CLICK,INPUT);
  
  //Pull analog pins high to enable reading of joystick movements
  digitalWrite(UP, HIGH);
  digitalWrite(DOWN, HIGH);
  digitalWrite(LEFT, HIGH);
  digitalWrite(RIGHT, HIGH);
  digitalWrite(CLICK, HIGH);
  
   tft.setCursor(25, 8);
   tft.setTextSize(1);
   tft.print(channel[current].name);
    tft.setCursor(90, 8);
    tft.setTextSize(1);
    tft.setTextColor(WHITE);
    tft.print(channel[current+1].name);
   ;
   //tft.print(channel[current+2].name);
   //tft.print(channel[current+3].name);

  //tft.fillScreen(BLACK);
  //tft.setCursor(0, 5);
  //tft.setTextColor(RED);  
  //tft.setTextSize(1);

 
}

void read_channel()
{
  unsigned char len = 0;
  unsigned char buf[8];
  //for(int i = 0; i<len; i++)
  {
  if(CAN_MSGAVAIL == CAN.checkReceive())           //check if data is on the bus
    {
    CAN.readMsgBuf(&len, buf);          //  read data, len: data length, buf: data buf
            // organize data for more resolution and accuracy
        a = (buf[1] + buf[0]);
        b = (buf[3] + buf[2]);
        c = (buf[5] + buf[4]);
        d = (buf[7] + buf[6]);
        
    }
  }
  if(a*3 < NR_OF_CHANNELS ) process_value(a*3,b);
  if(a*3+1 < NR_OF_CHANNELS ) process_value(a*3+1,c);
  if(a*3+2 < NR_OF_CHANNELS ) process_value(a*3+2,d);
}
void process_value( int ch, int val )
{
  int value = val * channel[ch].multiplier / channel[ch].divisor + channel[ch].offset;
  channel[ch].value = value;
  if (value > channel[ch].max_value ) channel[ch].max_value = value;
  if (value < channel[ch].min_value ) channel[ch].min_value = value;
}

void display_page() {
  //static int old_page;
  //if(old_page!=current); //Tft.fillScreen();
  //old_page=current;
  int disp_values[4];
  for ( int i = 0; i < 4; i++ )
  {
    switch (page_type) {
      case MIN:
        disp_values[i] = channel[current+i].min_value;
        break;
      case MAX:
        disp_values[i] = channel[current+i].max_value;
        break;
      default:
        disp_values[i] = channel[current+i].value;
     }
  }
    tft.setCursor(0, 17);
    tft.setTextSize(3);
    tft.setTextColor(GREEN);
    tft.print(disp_values[0]);
    //tft.drawNumber(disp_values[1],130,90,3,RED);
   //tft.drawNumber(disp_values[2],130,180,3,YELLOW);
   //tft.drawNumber(disp_values[3],130,270,3,BLUE);
}

void loop() {
  for(int i=0;i<NR_OF_CHANNELS;i++ )  read_channel();
  if (millis()-500 > last_click  && flip_request )
  {
    current+=4;
    if (current > NR_OF_CHANNELS - 4) current=0;
    last_click = millis();
    flip_request = 0;
 }

 flip_request = 0;
 display_page();
 //delay(30);
 //Tft.fillRectangle(130, 8, 80,25,BLACK);
 //Tft.fillRectangle(130, 88, 80,25,BLACK);
 //Tft.fillRectangle(130, 178, 80,25,BLACK);
 //Tft.fillRectangle(130, 268, 80 ,25,BLACK);
 print_to_serial();
 {
  if (digitalRead(CLICK) == 0) 
  flip_page();}
}

void print_to_serial()
{
  Serial.print(millis());
  for( int i = 0; i < NR_OF_CHANNELS ; i++ ) {
    if(i) Serial.print(",");
    else Serial.print(":");
    Serial.print(channel[i].name);
    Serial.print("=");
    Serial.print(channel[i].value);
  }
  Serial.println();
}

//void clear_lcd(void){
  //sLCD.write(COMMAND);
  //sLCD.write(CLEAR);


This is the error I get this also has a screen attached, sorry for the excess.
Code:
initializing can
Enter setting mode failed
 
What Teensy are is this connected to and is there a pic of that to show wiring? The LED can be ignored with pin 13 unchanged.

Was wondering about display and then this ... " this also has a screen attached"

If this is a Teensy using true SPI hardware would be right and starting without the screen and getting CAN working alone might be better to start - knowing the screen in the end might be important to make sure it has a Teensy ready driver.

Also would help having a link posted for the CAN shield
 
http://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/

Thank you for the reply
above is the link for the can bus shield.

its a teensy 3.2, I got the screen working. I know I went a little backwards on this and got the screen working first lol, but I want to make sure that it worked and it does exactly as expected. the screen is an adafruit oled 1.5.
 
Status
Not open for further replies.
Back
Top