I am extracting the weight
of a Reach Stacker
, for the moment this is my result
:
get data from ID:
18FFF227
2 1 F0 3C 0 0 1 0
what I need is to take F0 3C 0 0
and change it to 0 0 3C F0
then convert it to number to decimal.
003CF0 = 15600
according to this page: enter link description here
this would be my number in decimal 15600
this my code :
#include <SPI.h>
#include "mcp_can.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial (3,2);
// 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;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
START_INIT:
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init ok!");
}
else
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
delay(100);
goto START_INIT;
}
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
// unsigned char canId = CAN.getCanId();
unsigned long canId = CAN.getCanId();
// canHex = 18FFF227;
Serial.println("-----------------------------");
Serial.println("get data from ID: ");
if (canId == 0x18FFF227) {
Serial.println(canId, HEX);
// Serial.println(canId);
mySerial.println("-----------------------------");
mySerial.println("get data from ID: ");
mySerial.println(canId,HEX);
//if(buf[0] == 2){
// for(int i = 0; i<len; i++) // print the data
// {
// Serial.print(buf[i], HEX);
// mySerial.print(buf[i], HEX);
// Serial.print("\t");
// mySerial.print("\t");
// }
// } // if 2
// } // if 1
Serial.print(buf[5],HEX);
Serial.print(buf[4],HEX);
Serial.print(buf[3],HEX);
Serial.print(buf[2],HEX);
Serial.println();
}
}
this my current result:
get data from ID:
18FFF227
003cf0
This is what I need:
get data from ID:
18FFF227 15600