Knihovna pro kód je zde (MB) : https://code.google.com/archive/p/mudbus/downloads .
Standartní ethernet shield a arduino UNO i MEGA makaji skvěle stačí naimportovat knihovnu do kódu ale tento kousek modulu se mi nedaří spojit s příkladem v odkazu. (MB)
Za rady a porady děkuji.
Knihovnu pro modul zkouším UIPEthernet odkaz zde ( https://www.tweaking4all.com/hardware/a ... -ethernet/ )
Ukazkové video:
https://www.youtube.com/watch?v=M4mVDnlnzSA
Aktuální fukční kód Arduino MEGA, Arduino UNO a ethernet shield s micro SD kartou:
Kód: Vybrat vše
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter1 (0x23);
BH1750 lightMeter2 (0x5C);
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_1 6
#define ONE_WIRE_BUS_2 7
//#define ONE_WIRE_BUS_3 8
//#define ONE_WIRE_BUS_4 9
OneWire oneWire_cidlo1(ONE_WIRE_BUS_1);
OneWire oneWire_cidlo2(ONE_WIRE_BUS_2);
//OneWire oneWire_cidlo3(ONE_WIRE_BUS_3);
//OneWire oneWire_cidlo4(ONE_WIRE_BUS_4);
DallasTemperature cidlo1(&oneWire_cidlo1);
DallasTemperature cidlo2(&oneWire_cidlo2);
//DallasTemperature cidlo3(&oneWire_cidlo3);
//DallasTemperature cidlo4(&oneWire_cidlo4);
//#include "Mudbus.h"
Mudbus Mb;
//Function codes 1(read coils), 3(read registers), 5(write coil), 6(write register)
//signed int Mb.R[0 to 125] and bool Mb.C[0 to 128] MB_N_R MB_N_C
//Port 502 (defined in Mudbus.h) MB_PORT
void setup()
{
uint8_t mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x51, 0x06 };
uint8_t ip[] = { 192, 168, 1, 3 };
uint8_t gateway[] = { 192, 168, 1, 1 };
uint8_t subnet[] = { 255, 255, 0, 0 };
Ethernet.begin(mac, ip, gateway, subnet); //gateway
//Avoid pins 4,10,11,12,13 when using ethernet shield
delay(500);
Serial.begin(9600);
lightMeter1.begin();
lightMeter2.begin();
pinMode(7, INPUT);
pinMode(8, OUTPUT);
pinMode(50, OUTPUT);
pinMode(51, OUTPUT);
}
void loop()
{
Mb.Run();
uint16_t lux1 = lightMeter1.readLightLevel();
uint16_t lux2 = lightMeter2.readLightLevel();
// Měření teploty čislem DS18B20
cidlo1.requestTemperatures();
cidlo2.requestTemperatures();
//cidlo3.requestTemperatures();
//cidlo4.requestTemperatures();
float teplota1 = cidlo1.getTempCByIndex(0);
teplota1= teplota1;
int t1 = teplota1 * 100;
float teplota2 = cidlo2.getTempCByIndex(0);
teplota2= teplota2;
int t2 = teplota2 * 100;
//float teplota3 = cidlo3.getTempCByIndex(0);
//teplota3= teplota3;
//int t3 = teplota3 * 100;
//float teplota4 = cidlo4.getTempCByIndex(0);
//teplota4= teplota4;
//int t4 = teplota4 * 100;
//Konec měření teploty čidlem DS18B20
//Analog inputs 0-1023
Mb.R[0] = t1; //pin A0 to Mb.R[0]
Mb.R[1] = t2;
Mb.R[2] = lux1;
Mb.R[3] = lux2;
//Mb.R[4] = analogRead(A4);
//Analog outputs 0-255
//analogWrite(6, Mb.R[6]); //pin ~6 from Mb.R[6]
//Digital inputs
//Mb.C[7] = digitalRead(7); //pin 7 to Mb.C[7]
//Digital outputs
//digitalWrite(8, Mb.C[8]); //pin 8 from Mb.C[8]
}