Firmware do rolet dla silniczka krokowego
Logowanie do strony konfiguracyjnej - 192.168.4.1:81, użytkownik: admin, hasło: password. I teraz działa. Dzięki.
Na podstawie kodu który udostępnił kolega wojtas567 udało mi się stworzyć soft dla dwóch rolet wykorzystujących silniczki krokowe i uln-y. Wyjścia IN1-IN4 są wspólne dla obu silników, wybór pomiędzy nimi jest po przez odcięcie im masy zasilającej z wykorzystaniem tranzystora npn.
Kod: Zaznacz cały
/**
* Supla.org NodeMCU WiFi minimal example
* Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>
*
* This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
*/
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>
#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>
#include "Stepper_28BYJ_48.h"
extern "C" {
#include "user_interface.h"
}
WiFiClient client;
ADC_MODE(ADC_VCC);
int relay_1_pin = 1; // Tx
int relay_2_pin = 3; // Rx
int relay_3_pin = 2; // D4
int relay_4_pin = 4; // D2
int stepper_1_pin = 15; // D8
int stepper_2_pin = 5; // D1
Stepper_28BYJ_48 stepper(13,12,14,16); // wyjście silnika (D7,D6,D5,D0)
// Setup Supla connection
const char* ssid = "abc";
const char* password = "123";
// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {
double t = -275;
switch(channelNumber) {
case 2:
t = WiFi.RSSI();
break;
case 3:
t = ESP.getVcc() / 1000.0;
break;
};
return t;
}
void setup() {
Serial.begin(115200);
delay(10);
pinMode(stepper_1_pin, OUTPUT);
pinMode(stepper_2_pin, OUTPUT);
SuplaDevice.setName("Roleta x2"); // zmiana nazwy mdułu w supla
// wifi_station_set_hostname("Roleta"); // lub tak jeżeli górna nie zadziała
WiFi.softAPdisconnect(true); // wyłączenie rozgłaszania sieci ESP
// WiFi.setOutputPower(10); //Ograniczanie mocy wyjściowej (0 - 20.5)
// Replace the falowing GUID
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
char GUID[SUPLA_GUID_SIZE] = {0x20,0x19,0x05,0x10,
mac[WL_MAC_ADDR_LENGTH - 6],
mac[WL_MAC_ADDR_LENGTH - 5],
mac[WL_MAC_ADDR_LENGTH - 4],
mac[WL_MAC_ADDR_LENGTH - 3],
mac[WL_MAC_ADDR_LENGTH - 2],
mac[WL_MAC_ADDR_LENGTH - 1],
0x02,0x12,0x34,0x56,0x78,0x90};
// lub pobieramy identyfikator urządzenia ze strony https://www.supla.org/arduino/get-guid i wprowadzamy wiersz wyżej
/*
* Having your device already registered at cloud.supla.org,
* you want to change CHANNEL sequence or remove any of them,
* then you must also remove the device itself from cloud.supla.org.
* Otherwise you will get "Channel conflict!" error.
*/
SuplaDevice.addRollerShutterRelays(relay_1_pin , // 0 - roleta - dwa przekaźniki
relay_2_pin , true); //
SuplaDevice.addRollerShutterRelays(relay_3_pin , // 1 - roleta - dwa przekaźniki
relay_4_pin , true); //
SuplaDevice.addDS18B20Thermometer(); // 2 - rssi
SuplaDevice.addDS18B20Thermometer(); // 3 - zasilanie
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"xxx", // SUPLA server address
123, // Location ID
"xyz"); // Location Password
SuplaDevice.setName("rolety sypialnia"); // zmiana nazwy mdułu w supla
}
void loop() {
SuplaDevice.iterate();
Roletka();
}
// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
_supla_int_t size = client.available();
if ( size > 0 ) {
if ( size > count ) size = count;
return client.read((uint8_t *)buf, size);
};
return -1;
};
int supla_arduino_tcp_write(void *buf, int count) {
return client.write((const uint8_t *)buf, count);
};
bool supla_arduino_svr_connect(const char *server, int port) {
return client.connect(server, 2015);
}
bool supla_arduino_svr_connected(void) {
return client.connected();
}
void supla_arduino_svr_disconnect(void) {
client.stop();
}
void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {
// Serial.println("WiFi init");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
}
Serial.print("\nlocalIP: ");
Serial.println(WiFi.localIP());
Serial.print("subnetMask: ");
Serial.println(WiFi.subnetMask());
Serial.print("gatewayIP: ");
Serial.println(WiFi.gatewayIP());
}
SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
SuplaDeviceCallbacks cb;
cb.tcp_read = &supla_arduino_tcp_read;
cb.tcp_write = &supla_arduino_tcp_write;
cb.eth_setup = &supla_arduino_eth_setup;
cb.svr_connected = &supla_arduino_svr_connected;
cb.svr_connect = &supla_arduino_svr_connect;
cb.svr_disconnect = &supla_arduino_svr_disconnect;
cb.get_temperature = &get_temperature;
cb.get_temperature_and_humidity = NULL;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
return cb;
}
void Roletka() {
int roleta_1 = 0;
int roleta_2 = 0;
if ( digitalRead(relay_1_pin) == LOW ) {
stepper.step(-1);
roleta_1 = 1;
}
if ( digitalRead(relay_2_pin ) == LOW ) {
stepper.step(1);
roleta_1 = 1;
}
if ( digitalRead(relay_3_pin) == LOW ) {
stepper.step(-1);
roleta_2 = 1;
}
if ( digitalRead(relay_4_pin ) == LOW ) {
stepper.step(1);
roleta_2 = 1;
}
if (roleta_1 && roleta_2) { //Potrzebne by obie mogły się kręcić naraz
digitalWrite(stepper_1_pin, HIGH);
digitalWrite(stepper_2_pin, HIGH);
}
else if (roleta_1 && !(roleta_2)) {
digitalWrite(stepper_1_pin, HIGH);
digitalWrite(stepper_2_pin, LOW);
}
else if (roleta_2 && !(roleta_1)) {
digitalWrite(stepper_1_pin, LOW);
digitalWrite(stepper_2_pin, HIGH);
}
}
Witam,
trafiłem na Twój filmik dotyczący rolety, chętnie bym spróbował zmajstrować takie dzieło, ale niestety trafiłem na przeszkody z Arduino, biblioteki zostały pobrane, URL w Preferencje dodany, biblioteki Supla pobrane, a wyskakują takie błędy :
trafiłem na Twój filmik dotyczący rolety, chętnie bym spróbował zmajstrować takie dzieło, ale niestety trafiłem na przeszkody z Arduino, biblioteki zostały pobrane, URL w Preferencje dodany, biblioteki Supla pobrane, a wyskakują takie błędy :
Kod: Zaznacz cały
UWAGA: biblioteka SuplaDevice działa na architekturze(/architekturach) avr i może nie być kompatybilna z obecną płytką która działa na architekturze(/architekturach) esp8266.
Executable segment sizes:
IROM : 256496 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 27964 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
DATA : 1264 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 1552 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 28512 ) - zeroed variables (global, static) in RAM/HEAP
Szkic używa 287276 bajtów (27%) pamięci programu. Maksimum to 1044464 bajtów.
Zmienne globalne używają 31328 bajtów (38%) pamięci dynamicznej, pozostawiając 50592 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
esptool.py v2.8
Serial port COM5
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 48:3f:da:48:54:56
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 291424 bytes to 213935...
Wrote 291424 bytes (213935 compressed) at 0x00000000 in 19.0 seconds (effective 122.5 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
QLQ pisze: ↑sob cze 29, 2019 9:49 am Trochę się pobawiłem i przerobiłem (jeszcze nie w pełni) kod aby działał z esp8266 i serwem - tu akurat MG90S. Tak jak kolega @espablo pisła powyżej.
Proszę kod. Podpowiedzcie proszę jak zrobić aby kod sterował serwem nie w zakresie 0-180st tylko cały czas się kręciło np w prawo albo lewo w zależności od przycisku w apce lub fizycznego.
https://youtu.be/LkIUjIszsS0
Podłączenie:
.
IMG_20190629_115859.jpg
Kod: Zaznacz cały
/** * Supla.org NodeMCU WiFi minimal example * Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl> * * This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE */ #include <srpc.h> #include <log.h> #include <eh.h> #include <proto.h> #include <IEEE754tools.h> // We define our own ethernet layer #define SUPLADEVICE_CPP #include <SuplaDevice.h> #include <lck.h> #include <WiFiClient.h> #include <ESP8266WiFiType.h> #include <ESP8266WiFi.h> #include <ESP8266WiFiScan.h> #include <ESP8266WiFiMulti.h> #include <WiFiServer.h> #include <ESP8266WiFiGeneric.h> #include <WiFiClientSecure.h> #include <ESP8266WiFiAP.h> #include <ESP8266WiFiSTA.h> #include <WiFiUdp.h> #include "Stepper_28BYJ_48.h" #include <Servo.h> Servo myservo; extern "C" { #include "user_interface.h" } WiFiClient client; ADC_MODE(ADC_VCC); int pos; // Setup Supla connection const char* ssid = "ssid"; const char* password = "k34345xxx9"; void setup() { Serial.begin(115200); pinMode(2,INPUT_PULLUP); pinMode(3,INPUT_PULLUP); myservo.attach(4); // pin sterujacy serwem myservo.write(0); Serial.println(pos); delay(10); SuplaDevice.setName("Roleta_R@F"); // zmiana nazwy mdułu w supla // wifi_station_set_hostname("Roleta"); // lub tak jeżeli górna nie zadziała WiFi.softAPdisconnect(true); // wyłączenie rozgłaszania sieci ESP // WiFi.setOutputPower(10); //Ograniczanie mocy wyjściowej (0 - 20.5) // Replace the falowing GUID uint8_t mac[WL_MAC_ADDR_LENGTH]; WiFi.macAddress(mac); char GUID[SUPLA_GUID_SIZE] = {0x20,0x19,0x05,0x10, mac[WL_MAC_ADDR_LENGTH - 6], mac[WL_MAC_ADDR_LENGTH - 5], mac[WL_MAC_ADDR_LENGTH - 4], mac[WL_MAC_ADDR_LENGTH - 3], mac[WL_MAC_ADDR_LENGTH - 2], mac[WL_MAC_ADDR_LENGTH - 1], 0x02,0x12,0x34,0x56,0x78,0x90}; // lub pobieramy identyfikator urządzenia ze strony https://www.supla.org/arduino/get-guid i wprowadzamy wiersz wyżej /* * Having your device already registered at cloud.supla.org, * you want to change CHANNEL sequence or remove any of them, * then you must also remove the device itself from cloud.supla.org. * Otherwise you will get "Channel conflict!" error. */ SuplaDevice.addRollerShutterRelays(1, // 0 roleta dwa przekaźniki 3, true); // SuplaDevice.addSensorNO(2); // 1 czujnik krańcowy Call SuplaDevice.addSensorNO(A0, true) SuplaDevice.begin(GUID, // Global Unique Identifier mac, // Ethernet MAC address "svr5.supla.org", // SUPLA server address 34324, // Location ID "3540"); // Location Password SuplaDevice.setName("roleta R@F"); // zmiana nazwy mdułu w supla } void loop() { SuplaDevice.iterate(); Roletka(); } // Supla.org ethernet layer int supla_arduino_tcp_read(void *buf, int count) { _supla_int_t size = client.available(); if ( size > 0 ) { if ( size > count ) size = count; return client.read((uint8_t *)buf, size); }; return -1; }; int supla_arduino_tcp_write(void *buf, int count) { return client.write((const uint8_t *)buf, count); }; bool supla_arduino_svr_connect(const char *server, int port) { return client.connect(server, 2015); } bool supla_arduino_svr_connected(void) { return client.connected(); } void supla_arduino_svr_disconnect(void) { client.stop(); } void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) { // Serial.println("WiFi init"); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); // Serial.print("."); } Serial.print("\nlocalIP: "); Serial.println(WiFi.localIP()); Serial.print("subnetMask: "); Serial.println(WiFi.subnetMask()); Serial.print("gatewayIP: "); Serial.println(WiFi.gatewayIP()); } SuplaDeviceCallbacks supla_arduino_get_callbacks(void) { SuplaDeviceCallbacks cb; cb.tcp_read = &supla_arduino_tcp_read; cb.tcp_write = &supla_arduino_tcp_write; cb.eth_setup = &supla_arduino_eth_setup; cb.svr_connected = &supla_arduino_svr_connected; cb.svr_connect = &supla_arduino_svr_connect; cb.svr_disconnect = &supla_arduino_svr_disconnect; // cb.get_temperature = &get_temperature; cb.get_temperature_and_humidity = NULL; cb.get_rgbw_value = NULL; cb.set_rgbw_value = NULL; return cb; } void Roletka() { if(digitalRead(3) == LOW) { if (pos <= 190) { pos++; Serial.println(pos); } myservo.write(pos); } delay(2); if (digitalRead(1) == LOW){ if (pos >= 0) { pos--; Serial.println(pos); } myservo.write(pos); } delay(2); }