Can Bus with 5 Devices

Hello everyone. Im stuying about arduino Can Bus project but i have some problem with it.

First of all the project has 1 arduino mega and 4 pro mini(they have servo motors), all of them will communicate with can bus module. In this project Arduino mega send the order all of the pro minis and pro minis -if they have work to do- start their works. But they are not starting. Modules couldnt do their jobs.

Can you help me please thank you

Also when i start modules i get only Can Bus OK message i cant get the feedback

alfamanager:
Hello everyone. Im stuying about arduino Can Bus project but i have some problem with it.

First of all the project has 1 arduino mega and 4 pro mini(they have servo motors), all of them will communicate with can bus module. In this project Arduino mega send the order all of the pro minis and pro minis -if they have work to do- start their works. But they are not starting. Modules couldnt do their jobs.

Can you help me please thank you

Also when i start modules i get only Can Bus OK message i cant get the feedback

oh yes sure we can help... the problem is so obvious!

oh wait... sorry we can't help solving your problem without your code or a schematic our you CAN network... or should we try a crystal ball??

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif
#include <SPI.h> //SPI is used to talk to the CAN Controller
#include <mcp_can.h>

MCP_CAN CAN(10);

/// Motor 1
const byte M1CWPin = 8; // INA: Clockwise input
const byte M1CCWPin = 7; // INB: Counter-clockwise input
const byte M1PWMPin = 5; // PWM input
const byte M1CurrentSensePin = A2; // CS: Current sense ANALOG input
const byte M1EnablePin = A0; // EN: Status of switches output (Analog pin)
byte varlik;
byte level;
byte gecti;
byte val;
byte sayac = 0;
byte sayac1 = 0;

unsigned char stmp1[1];
unsigned char stmp2[3];

unsigned char len = 0;
unsigned char buf[1];
unsigned int canID;

int Led = 13 ;// define LED Interface
int Pin2 = 9;
int Pin3 = 15;
int Pin4 = 4;
int Pin5 = 3;

int Name ;

byte hitObject = false;

int Item = 4;

long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)

#define PIN 6
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

Serial.begin(115200); // Initiates the serial to do the monitoring
Serial.println("module");
Serial.println(); //Print function list for user selection
stmp1 [0]= char (Item);
for (int i = 1 ; i <= 1; i++)
{
stmp1 = 0;

  • }*

  • stmp1 [1] |= (1 << 0);*

  • stmp1 [1] |= (1 << 1);*

  • stmp1 [1] |= (1 << 2);*

  • stmp2 [2] |= (1 << 0);*

  • stmp2 [2] |= (1 << 1);*

  • stmp2 [2] |= (1 << 2);*
    START_INIT:

  • if (CAN_OK == CAN.begin(CAN_250KBPS)) *

  • {*

  • Serial.println("CAN BUS Shield init ok!");*

  • }*

  • else*

  • {*

  • Serial.println("CAN BUS Shield init fail");*

  • Serial.println("Init CAN BUS Shield again");*

  • _delay_us(100);*

  • goto START_INIT;*

  • }*

  • pixels.begin(); // This initializes the NeoPixel library.*

  • pinMode (Led, OUTPUT) ;// define LED as output interface*

  • pinMode (Pin2, INPUT) ;// define the obstacle avoidance sensor output interface*

  • pinMode (Pin3, INPUT) ;// define the obstacle avoidance sensor output interface*

  • pinMode (Pin4, INPUT) ;// define the obstacle avoidance sensor output interface*

  • pinMode (Pin5, INPUT) ;// define the obstacle avoidance sensor output interface*

  • pinMode (M1CWPin, OUTPUT);*

  • pinMode (M1CCWPin, OUTPUT);*

  • digitalWrite(M1CWPin, LOW);*

  • digitalWrite(M1CCWPin, LOW);*

}
void loop ()
{

  • if (CAN_MSGAVAIL == CAN.checkReceive()) //check if data coming*

  • {*

  • CAN.readMsgBuf(&len, buf); //read data, len: data length, buf: data buffer*

  • canID = CAN.getCanId(); //getting the ID of the incoming message*

  • if (canID == 0xA0) //reading only our beloved 0x01 message*

  • {*

  • Paksay = buf[0];*

  • while ((sayac <= Item) && (digitalRead (Pin2) == LOW))*

  • {*

  • stmp2 [2] |= (1 << 0);*

  • seviye = digitalRead (Pin3) ;*

  • if (level== LOW)*

  • {*

  • green ();*

  • Serial.println("OK! ");*

  • stmp2 [1] |= (1 << 0);*

  • }*

  • else*

  • {*

  • blue ();*

  • Serial.println ("Not OK!" ) ;*

  • stmp2 [1] &= ~(1 << 0);*

  • }*

  • throw ();*

  • }*

  • for (int i = 0 ; i <= 7; i++)*

  • {*

  • int y = (buf [1] >> i ) & 1;*

  • Serial.print(" ");*

  • Serial.print(y);*

  • }*

  • Serial.println();*
    _ Serial.println("\n\t*************");_

  • }*

  • }*

  • stop ();*

}
void throw () {

  • const byte say = sayac;*

  • motor ();*

  • digitalWrite(Led, LOW);*

  • // delay (300);*

  • while ((say == sayac) && (digitalRead (UrunVarPin) == LOW))*

  • {*

  • int val = digitalRead(Pin4);*

  • if ( (val == 0) && (hitObject == false))*

  • {*

  • hitObject = true;*

  • sayac ++;*

  • Serial.println(" ... ATTIM ");*

  • digitalWrite(Led, HIGH);*

  • gone();*

  • stmp2 [3] |= (1 << 0);*

  • }*

  • else if ( (val == 1) && (hitObject == true))*

  • {*

  • hitObject = false;*

  • stmp2 [1] &= ~(1 << 0);*

  • }*

  • }*

  • if (digitalRead (Pin2) == HIGH)*

  • {*

  • stop ();*

  • Serial.println("Out of item");*

  • stmp2 [2] &= ~(1 << 0);*

  • }*
    }
    void gone () {

  • const byte say = sayac1;*

  • while ((say == sayac1) && (digitalRead (UrunVarPin) == LOW ))*

  • {*

  • int val = digitalRead(Pin5);*

  • if ( (val == 0) && (hitObject == false))*

  • {*

  • hitObject = true;*

  • sayac1 ++;*

  • Serial.println("Gone ");*

  • digitalWrite(Led, HIGH);*

  • stmp1 [1] |= (1 << 0);*

  • }*

  • else if ( (val == 1) && (hitObject == true))*

  • {*

  • delay (2000);*

  • hitObject = false;*

  • Serial.println ("stuck");*

  • stop();*

  • stmp1 [1] &= ~(1 << 0);*

  • }*

  • }*
    _ /* if (digitalRead (Pin5) == HIGH)_

  • {*

  • stop ();*

  • Serial.println("stayed ");*
    _ }*/_

  • if (hitObject == false)*

  • {*

  • Serial.println("stayed ");*

  • dur ();*

  • stmp1 [1] &= ~(1 << 0);*

  • }*

  • CAN.sendMsgBuf(0x10, 0, 2, stmp1,stmp2);*
    }
    void motor() {

  • /////////////////////////////*

  • // Motor 1 ClockWise*

  • digitalWrite(M1CWPin, HIGH);*

  • // Motor full speed*

  • analogWrite(M1PWMPin, 255);*
    }
    void stop()
    {

  • red ();*

  • digitalWrite(M1CWPin, LOW);*
    }
    void red ()
    {

  • pixels.setPixelColor(0, pixels.Color(10, 0, 0)); // Moderately bright red color.*

  • pixels.show(); // This sends the updated pixel color to the hardware.*
    }
    void green ()
    {

  • pixels.setPixelColor(0, pixels.Color(0, 10, 0)); // Moderately bright green color.*

  • pixels.show(); // This sends the updated pixel color to the hardware.*
    }
    void blue ()
    {

  • pixels.setPixelColor(0, pixels.Color(0, 0, 10)); // Moderately bright blue color.*

  • pixels.show(); // This sends the updated pixel color to the hardware.*
    }
    this is reciever code. it also has to send data to mega

first: please read the how to use this forum and learn how to post code. If you know how to post code - edit your post.

second: tell us: which canbus library you are using. post a LINK (clickable!) to your library

third: tell us: have you successfully tried the can_send and can_receive example - which are coming with most of the libraries, and were these examples sucessfull with your hardware?

I've got library from github (the guy i totally cant remember his name).

Now can you help me for this situation?