Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************
- Souliss - Android Control for RGB Led/Strip, FAN, Relay, TEMP DB18B20 & AC712
- for Current and Watt Sensor
- This is using Arduino pro mini board connected to ESP8266 using hardware
- TX and RX
- Run this code on one of the following boards:
- - Arduino with ESP8266 connected using hardware serial TX & RX
- - ESP TX to Arduino RX, ESP RX to Arduino TX
- - For Arduino 5V use Shift Leveling for TX/RX Pin
- ***************************************************************************/
- // Configure the framework
- #include "bconf/StandardArduino.h" // Use a standard Arduino
- #include "conf/usart.h" // USART for ESP8266
- // Include framework code and libraries
- #include <SPI.h>
- #include "Souliss.h"
- #include "extras/extras.h"
- #include <OneWire.h>
- #include <DallasTemperature.h>
- // Define the network configuration according to your router settings
- #define myvNet_subnet 0xFF00
- #define Gateway_RS485 0xD001
- #define Peer_RS485 0xD002
- //Define Slot Number
- #define LEDCONTROL 0 // This is the memory slot for the logic that handle the light
- #define LEDRED 1 // This is the memory slot for the logic that handle the light
- #define LEDGREEN 2 // This is the memory slot for the logic that handle the light
- #define LEDBLUE 3 // This is the memory slot for the logic that handle the light
- #define MYLEDLOGIC 4 // This is the memory slot for the logic that handle the light
- #define FAN 5 // This is the memory slot for the logic that handle the light
- #define TEMPERATURE 7
- #define TEMPERATURE1 9
- #define CURRENT 11
- #define WATTS 13
- #define DEADBAND 0.01 // Deadband value 5%
- #define DEADBAND1 0.01 // Deadband value 5%
- //Arduino Pin, use pin 7
- #define ONE_WIRE_BUS 7
- OneWire oneWire(ONE_WIRE_BUS);
- // Pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors(&oneWire);
- DeviceAddress Ujung = {0x28, 0xFF, 0x01, 0x33, 0x02, 0x15, 0x04, 0x78};
- DeviceAddress Deket = {0x28, 0xFF, 0xCB, 0x2C, 0x02, 0x15, 0x04, 0x45};
- //Variable for Current & Watts
- const int analogIn = A0;
- int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
- int RawValue= 0;
- int ACSoffset = 2500;
- float Voltage = 0;
- float VDC = 0;
- float Amps = 0;
- void setup()
- {
- // Serial.begin(115200);
- Initialize();
- // Set network parameters
- SetAddress(Peer_RS485, myvNet_subnet, Gateway_RS485);
- // Set a logic to control a RGB LED, Relay, Fan, Temp, Current & Watts
- Set_LED_Strip(LEDCONTROL);
- Set_SimpleLight(MYLEDLOGIC);
- Set_DimmableLight(FAN);
- Souliss_SetT52(memory_map, TEMPERATURE);
- Souliss_SetT52(memory_map, TEMPERATURE1);
- Set_Current(CURRENT);
- Set_Power(WATTS);
- pinMode(2, INPUT); // Hardware pulldown required (button)
- pinMode(9, OUTPUT); // Power the LED Red
- pinMode(5, OUTPUT); // Power the LED Green
- pinMode(6, OUTPUT); // Power the LED Blue
- pinMode(10, OUTPUT); // Power the LED (relay)
- pinMode(3, OUTPUT); // Power the Fan
- // Start up the DALLAS library
- sensors.begin();
- sensors.setResolution(Ujung, 10);
- sensors.setResolution(Deket, 10);
- }
- void loop()
- {
- // Here we start to play
- EXECUTEFAST() {
- UPDATEFAST();
- // Read every 10ms the input state and send it to the other board
- FAST_10ms() {
- // Retreive data from the MaCaco communication channel
- Souliss_CommunicationData(memory_map, &data_changed);
- // Compare the acquired input with the stored one, send the new value to the
- // user interface if the difference is greater than the deadband
- Souliss_Logic_T52(memory_map, TEMPERATURE, DEADBAND, &data_changed);
- Souliss_Logic_T52(memory_map, TEMPERATURE1, DEADBAND1, &data_changed);
- // Use Pin2 as command
- if (DigIn(2, Souliss_T1n_ToggleCmd, LEDCONTROL))
- mInput(MYLEDLOGIC) = mInput(LEDCONTROL);
- // Execute the logic that handle the LED
- Logic_LED_Strip(LEDCONTROL);
- // Use the output values to control the PWM
- analogWrite(9, mOutput(LEDRED));
- analogWrite(5, mOutput(LEDGREEN));
- analogWrite(6, mOutput(LEDBLUE));
- Logic_SimpleLight(MYLEDLOGIC);
- DigOut(10, Souliss_T1n_Coil,MYLEDLOGIC);
- Logic_DimmableLight(FAN);
- analogWrite(3, mOutput(FAN+1));
- }
- FAST_510ms() {
- Logic_Current(CURRENT);
- Logic_Power(WATTS);
- }
- // Here we handle here the communication with Android, commands and notification
- FAST_PeerComms();
- }
- EXECUTESLOW()
- {
- UPDATESLOW();
- SLOW_10s() {
- //Serial.print("Requesting temperatures...");
- sensors.requestTemperatures(); // Send the command to get temperatures
- //Serial.println("DONE");
- //Serial.print("Temperature for Device Ujung is: ");
- // float temperature = sensors.getTempCByIndex(0);
- float temperature = sensors.getTempC(Ujung);
- //Serial.println (temperature);
- Souliss_ImportAnalog(memory_map, TEMPERATURE, &temperature);
- // float temperature1 = sensors.getTempCByIndex(1);
- //Serial.print("Temperature for Device Dekat is: ");
- float temperature1 = sensors.getTempC(Deket);
- //Serial.println (temperature1);
- Souliss_ImportAnalog(memory_map, TEMPERATURE1, &temperature1);
- // The timer handle timed-on states
- Timer_LED_Strip(LEDCONTROL);
- RawValue = analogRead(analogIn);
- Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
- VDC = ((RawValue / 1023.0) * 5000/2)/100; // Gets you mV
- Amps = ((Voltage - ACSoffset) / mVperAmp);
- float watt = VDC * Amps;
- // Serial.print("\t mV = "); // shows the voltage measured
- // Serial.print(VDC); // the '3' after voltage allows you to display 3 digits after decimal point
- // Serial.print("\t Amps = "); // shows the voltage measured
- // Serial.println(Amps); // the '3' after voltage allows you to display 3 digits after decimal point
- // delay(2500);
- Souliss_ImportAnalog(memory_map, CURRENT, &Amps);
- Souliss_ImportAnalog(memory_map, WATTS, &watt);
- }
- }
- START_PeerJoin(); //tell gateway that i am exist
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement