Hello Guest it is December 13, 2019, 03:32:16 PM

Author Topic: Modbus and Arduino Question  (Read 14828 times)

0 Members and 1 Guest are viewing this topic.

Re: Modbus and Arduino Question
« Reply #10 on: October 12, 2016, 09:21:33 PM »
Nice pendant
Rob

Albert Einstein ― “If you can't explain it to a six year old, you don't understand it yourself.”
Re: Modbus and Arduino Question
« Reply #11 on: October 16, 2016, 11:00:14 AM »
Thank you!

Erik
Re: Modbus and Arduino Question
« Reply #12 on: January 29, 2017, 05:58:06 PM »
@ejjenkins

I'm trying to build everything using a pendant with modbus based on an Arduino Mega 2560 or a smaller one, but I do not understand the brain programming or how the data come to the display in the Arduino.

I would be very happy if I would get the files from you.

Thank you
Re: Modbus and Arduino Question
« Reply #13 on: January 31, 2017, 06:05:01 AM »
I can help with brans but I need arduino code...
Re: Modbus and Arduino Question
« Reply #14 on: January 31, 2017, 03:41:33 PM »
I use the corrected Arduino Code from Schilling, because there bugs in it. With the right one i test Buttons and Signal-output but no LCD on it. A second example code for a pedant gives me no connection to Mach3, but it is not for Modbus. I think it's for LinuxCNC. I can test it with a Terminal-program.
Re: Modbus and Arduino Question
« Reply #15 on: January 31, 2017, 04:39:38 PM »
How you is conected lcd to arduino.is it i2c or serial or parallel lcd
Re: Modbus and Arduino Question
« Reply #16 on: January 31, 2017, 04:43:10 PM »
It is i2c with a 20x4 LCD and a 4x5 keyboard matrix also connected. Is it possible to wire it with Mach3 serial bus?
Re: Modbus and Arduino Question
« Reply #17 on: January 31, 2017, 04:44:19 PM »
SEND MY YOUR MAIL
Re: Modbus and Arduino Question
« Reply #18 on: January 31, 2017, 04:47:58 PM »
Code: [Select]
// Modbus:
#include <SimpleModbusSlave.h> //http://code.google.com/p/simple-modbus/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

const int HOLDING_REGS_SIZE = 22; // I use 22 registers, first 11 for sendidng info to Mach3
//and next 11 registers for receiving info from Mach3
unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array

int rcd[11]; //holds sending info
int mcd[11]; //holds received info

void setup(){

  pinMode(13, OUTPUT); //indicator LED

  modbus_configure(&Serial, 115200, SERIAL_8N2, 2, 13, HOLDING_REGS_SIZE, holdingRegs);
//2 is slave address, 13 is indicator led pin (useless)
 lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines, turn on backlight
 lcd.print("Hello, ARDUINO ");  
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print (" FORUM - fm   ");
  delay ( 1000 );
  
}

void loop(){

  //Reads buttons:
  if(digitalRead(4) == 1) bitSet(rcd[0],0);
  else bitClear(rcd[0],0);

  if(digitalRead(5) == 1) bitSet(rcd[0],1);
  else bitClear(rcd[0],1);

  if(digitalRead(6) == 1) bitSet(rcd[0],2);   //can be up to 15
  else bitClear(rcd[0],2);

  //Potens´iometers:
  rcd[3] = analogRead(A0);
  rcd[4] = analogRead(A1);

  //Other variables:
  rcd[1] = 0x1111;
  rcd[2] = 0x2222;
  rcd[5] = 0x3333;
  rcd[6] = 32767;
  rcd[7] = 12345;
  rcd[8] = 54321;
  rcd[9] = 0;
  rcd[10] = 1;


  //Sending and receiving info:
  for (int i=0; i < 11; i++)
    holdingRegs[i] = rcd[i];

  modbus_update();

  for (int i=0; i < 11; i++)
    mcd[i] = holdingRegs[i+11];

  // Writes cordinates to LCD:
   float Xpos = mcd[0]+(mcd[1]/100.00);
   float Ypos = mcd[2]+(mcd[3]/100.00);
   float Zpos = mcd[4]+(mcd[5]/100.00);
  
   lcd.setCursor( 0,0 );
   lcd.print("                ");
   lcd.setCursor( 0, 0 );
   lcd.print("X");
   lcd.setCursor( 1, 0 );
   lcd.print(Xpos);
   lcd.setCursor( 0, 1 );
   lcd.print("                ");
   lcd.setCursor( 0, 1 );
   lcd.print("Y");
   lcd.setCursor( 1, 1 );
   lcd.print(Ypos);
   lcd.setCursor( 0, 2 );
   lcd.print("                ");
   lcd.setCursor( 0, 2 );
   lcd.print("Z");
   lcd.setCursor( 1, 2 );
   lcd.print(Zpos);
   lcd.setCursor(0, 3);
   lcd.print("                ");
   lcd.setCursor(0, 3);
   lcd.print("A");
  
  

}
  
Re: Modbus and Arduino Question
« Reply #19 on: January 31, 2017, 04:49:45 PM »
I send you per IM