Recent Posts

Pages: [1] 2 3 ... 10
Deutsch / Modbus RTU RS485 - Master und ...
Last post by stfan1409 - Today at 01:25 pm

ich möchte einen Mega2560 als Modbus Master im Halbduplex betreiben. Dieser soll Daten an "Arduino Nano Slave1" senden und Daten abfragen. Dasselbe mit "Slave2"... Dazu habe ich einen TTL <-> RS485 Wandler an jeden Arduino angeschlossen und benutze <SimpleModbusMaster.h>(standart, nicht DUE).

Erster Versuch mit 2 Nanos(Master und Slave) war erfolgreich. Dann habe ich den einen Nano gegen einen Mega getauscht - funktioniert. Nun möchte ich aber nicht TX0 und RX0 sondern TX1 und RX1 am Mega nutzen, aber es kommen keine Daten mehr...?

Geändert habe ich nur von " &Serial " auf " &Serial1 "

modbus_configure(&Serial1, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);

Was muss noch geändert werden damit es an Serial1 funktioniert?

Hier das Testprogramm vom Master:
Code: [Select]
#include <SimpleModbusMaster.h> //Modbus
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <SPI.h>

#define TFT_CS        10 // Hallowing display control pins: chip select
#define TFT_RST       8 // Display reset
#define TFT_DC        9 // Display data/command select
// For 1.44" and 1.8" TFT with ST7735 (including HalloWing) use:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

#define TxEnablePin 2                                                           // RS485 Umschaltpin senden/empfangen
#define baud 9600  //Baudrate Modbus
#define SlaveID 2             //ID vom Slave
#define timeout 1000
#define polling 20 // the scan rate, standard was 200
#define retry_count 10

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 8                                          // Anzahl der Sende- und Empfangsdaten(ges.)

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
  PACKET1,                                          // set 4 registers
  PACKET2,                                          // read 4 registers
  TOTAL_NO_OF_PACKETS // leave this last entry

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS]; //Register zum Senden/Empfangen
unsigned long previousMillis;

void setup()
  //Display ST7735:
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab
  tft.setRotation(1); //Where rotation is 0, or 2 for portrait and 1 or 3 for landscape rotations.
  uint16_t time = millis();
  time = millis() - time;

  // Initialize each packet: packet, slave-id, function, start of slave index, number of regs, start of master index
  // set 4 registers
  // read 4 registers

  modbus_construct(&packets[PACKET1], SlaveID, PRESET_MULTIPLE_REGISTERS, 0, 4, 0); //Register an den Slave SENDEN
  modbus_construct(&packets[PACKET2], SlaveID, READ_HOLDING_REGISTERS, 4, 4, 4);   //Register vom Slave EMPFANGEN

  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);

void loop()

  modbus_update();                          // send Master request to Slave, as defined above


  if (millis() - previousMillis > 500) {

//Werte an Slave:
    regs[0] = 6;
    regs[1] = 1;
    regs[2] = 2;
    regs[3] = 3;


    previousMillis = millis();


void Anzeige() {

  tft.setTextWrap(false);               //Zeilenumbruch
  tft.fillScreen(ST77XX_WHITE);         //Hintergrundfarbe festlegen
  tft.setTextColor(ST77XX_BLACK);       //Schriftfarbe festlegen
  tft.setTextSize(2);                   //Schriftgröße

  tft.setCursor(0, 0);                  //Position setzen: von links, von oben
  //tft.println("Counter: ");             //TEXT
  tft.setCursor(100, 0);                 //Position setzen: von links, von oben
  //tft.println(counter % 8 + 1);                //TEXT

  tft.setCursor(0, 25);                 //Position setzen: von links, von oben
  tft.println("regs[4]: ");                //TEXT
  tft.setCursor(100, 25);                 //Position setzen: von links, von oben

  tft.setCursor(0, 50);                 //Position setzen: von links, von oben
  tft.println("regs[5]: ");                //TEXT
  tft.setCursor(100, 50);                 //Position setzen: von links, von oben
  tft.setCursor(0, 75);                 //Position setzen: von links, von oben
  tft.println("regs[6]: ");                //TEXT
  tft.setCursor(100, 75);                 //Position setzen: von links, von oben

  tft.setCursor(0, 100);
  tft.println("regs[7]: ");                //TEXT
  tft.setCursor(100, 100);                 //Position setzen: von links, von oben


while buying router tables there are  things that we are supposed to keep in mind and it depends from person to person what type of product he or she wants , because every one has their own requirements and budgets hence you can go through this reviews it would be really very use full to you guys i personally got guided by this hence thought of sharing this !
unbiased reviews for best router tables 2019.
Project Guidance / Re: Connecting 28 "devices" to...
Last post by DaRkBoDoM - Today at 01:23 pm
What's "RX485"? If you mean RS-485, a controller with multiple serial devices is almost inevitable. Get a Mega and be happy without any tricks.
Yep, it's RS-485, sorry. I do not need any serial to drive it. The Mega seems to be a bit of an overkill.
Website and Forum / LCD Printing Garbage
Last post by Bhysjulien - Today at 01:23 pm
Hello... For some reason with this code (and this code only) my LCD prints garbage. It appears the garbage on the display updates on correct time intervals but the screen always picks garbage. I can provide a pin digarm but I am pretty sure these are all connect correctly.

If I load a example code onto my board using "LiquidCrystal lcd(1,2,4,5,6,7); " as how the board is connected the display is correct.

Any help would be great! I've been staring at this far to long now.  I'm assuming it has to do with my set up because it prints garbage from the very start.

Note: I was not able to upload all my subroutines. If needed I can provide but these put my post out of range of the allowed characters.

Code: [Select]

#include <Wire.h>
#include <LiquidCrystal.h>
#include "BlueDot_BME280.h"
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.   
#include <Keypad.h>

LiquidCrystal lcd(1,2,4,5,6,7);

bool temp_message = false;
bool before_logic_message = false;   
bool after_hb_check_message = false;
bool heart_beat_message = false;   
bool door_flag = false;
bool keyPadCheck_flag = false;
bool load_value_flag = false;
bool correct_value_flag = false;
bool pw_flag = false;
bool keyPad_Flag1 = false;
bool keypad_Flag2 = false;
bool math_flag = false;
bool temp_flag = false; //*************************************************ONCE FINISHING PROGRAM RESET TO FALSE! SET TO TRUE WHILE WRITING KEY PAD CODE*************************
bool flag_Entry = true;
bool flag_heartbeat =false;

//Key pad variable
int logic_sum = 0;
int fails = 0;
int math_tries = 0;
int key;
int value;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
int padCount = 0;

int j = 2;
int i = 0;
byte rowPins[ROWS] = {24, 23, 22, 19}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {27, 26, 25}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char* secretCode = "1234";
int position = 0;

//TEMP and Humidity variable
BlueDot_BME280 bme1;                                     //Object for Sensor 1
BlueDot_BME280 bme2;                                     //Object for Sensor 2

int bme1Detected = 0;                                    //Checks if Sensor 1 is available
int bme2Detected = 0;                                    //Checks if Sensor 2 is available

float temp_read1 = 0;
float temp_read2 = 0;

//heartbeat variables
const int PulseWire = 0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13;          // The on-board Arduino LED, close to PIN 13.
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
PulseSensorPlayground pulseSensor; //Creates a pulseSensor object.

void setup()
  pinMode(14, LOW); //Reading int from Pulse sense on Uno.   
  //if (pulseSensor.begin())
  //Serial.println("We created a pulseSensor Object !");  //This prints one time at Arduino power-up,  or on Arduino reset. 

void loop() {
 // Serial.println("PUtting something on the screen");
  key = keypad.getKey();
  if(flag_Entry == true)
      if(bme1Detected && temp_flag == false)
        lcd.print("Lets take your temp");

      if(temp_flag == true && temp_message == false)
         lcd.print("You may not be infected");
         lcd.print("But lets make sure");
         lcd.print("Lets check...");
         lcd.print("your heart rate"); 
         temp_message = true;

          if(temp_flag == true && flag_heartbeat == false)
         int uno_read_dig = digitalRead(14);
         if(uno_read_dig == HIGH)
            flag_heartbeat = true;
            flag_heartbeat = false;

      if(flag_heartbeat == true && after_hb_check_message == false)
        lcd.print("You're not dead");
        lcd.print("But can you do");
        lcd.print("Please push *");
        after_hb_check_message = true;
      if(flag_heartbeat == true && after_hb_check_message == true)
        if(keyPadCheck_flag == false)
      if(flag_heartbeat == true && after_hb_check_message == true && keyPadCheck_flag == true && before_logic_message == false)
         lcd.print("please do a...");
         lcd.print("litte math!");
         before_logic_message = true;   

      if(keyPad_Flag1 == true && before_logic_message == true)
         if(load_value_flag == false)
         math_input(); //Loads two varibles and outputs values on to
         key = 0;
      if(load_value_flag == true && key !=0)
          if(math_tries < 2)
             load_value_flag = false;
             math_tries = 0;
             fails ++;
       if(pw_flag == true && key != '*')
            position = 0;
       if(key == secretCode[position])
       else if(key != secretCode[position] && key != 0 && key != '*')
            position = 0;
            fails ++;
       if(position == 4)
       if(door_flag == true)
          //call subroutine for unlocking door.
          //Serial.print("The door is unlocked");
  if(fails == 2)
      //trigger defense.   

Thanks for the link. I also read the 6050 datasheet, so let's see if i understand it correctly:

The mpu6050 has the full-scale range between +-2 and +-16g.
So the library uses +-2 g (16,384 LSB/g), because of these lines:

Code: [Select]
accX = ((float)rawAccX) / 16384.0;
accY = ((float)rawAccY) / 16384.0;
accZ = ((float)rawAccZ) / 16384.0;

When my mpu6050 is lieing on the table, I get this output:

Code: [Select]
accX : -0.05 accY : -0.01 accZ : 1.07

So the mpu6050 reads the gravity on z-axis with 1.07 g, right? So all the data is in g.
1,07 g = 10,49 m/s²
If I multiply all the output with 9.806, I should get the wanted m/s² output?
Or am I failing in math currently?  :smiley-red:
MKRGSM1400 / TinyGPS++ library
Last post by alphacat92 - Today at 01:20 pm
Hello, I'm having a lot of trouble using the TinyGPS++ library with the MKR GSM 1400. I understand that the MKR does not have software serial capabilities so I've been trying to get the library to work using hardware serial. Here is my code, but when I connect it properly I don't get output. I tested it with a Nano and it worked:
Code: [Select]

#include <TinyGPS++.h>

//Initialize TinyGPS++ object
TinyGPSPlus gps;

void setup() {
  //while (!Serial);

void loop() {
  while (Serial.available() > 0)
    if (gps.encode(
      if (gps.location.isValid())
        Serial.print(, 6);
        Serial.print(", ");
        Serial.print(gps.location.lng(), 6);
        delay (1000);
options, lots of options

RS-485 relay board.  move all relays off the micro onto the existing RS-485 bus.
SPI Shift register 
I2C port expander - MCP23017 for 16 pins   or PCF8574 for 8 pins

I2C relay board

Audio / Re: FFT behaviour when everyth...
Last post by Gereon99 - Today at 01:19 pm
Thank you very much for these explanations. And also thanks for tips on how to improve the code! :)
Project Guidance / Re: Arduino Operating System
Last post by akouz - Today at 01:18 pm
Last bug, here's the fix --
BTW, in your code after reset the second LED starts with 0.9 sec pause, not with a blink. You may claim it was intentional... :)

I'd really like to know if using this library means I won't have any bugs in the code that contains it.
Bugs are less probable because with OS code is more transparent.
I dont even know if println(UID) is correctly put..
1.  Serial.println(UID); is composed of:
Code: [Select]
Serial.println();           //this line brings the cursor at the next new line position

2.  print() method always presents human friendly text message (as a series of English Language characters.

3. Using this directive: #define, you can represent a numerical value/expression by a symbolic name; but, the expression must be evaluated to a numerical value; For example:

Code: [Select]
#define UID (1+3)
#define UID {0xDE, 0xAB, 0xFF, 0x3B}   //It is not valid as the expression can't be evaluated to a value

4.  You can do the following:
Code: [Select]
byte UID[] = {0xDE, 0xAB, 0xFF, 0x3B}; //data type is byte because the array elements are in binary

5.  You can also do the following:
Code: [Select]
char myData [] = {0x31, 0x32, 0x33, 0x34, 0x00}; //data type is char because the array elements are in ASCII
Serial.print(myData); //shows: 1234


Pages: [1] 2 3 ... 10