• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
sterowanie roletami
#11
(16-11-2016, 22:22)Ghost1991 napisał(a): Pytanie z mojej strony bo jestem zainteresowany budową takiego układu, czy da się odczytać pozycję rolety gdy np opuścimy ją ręcznie powiedzmy o 1/3 okna. ja chciałem mieć rolety sterowane arduino ale też normalnym włącznikiem gdy nie będę miał akurat telefonu przy sobie a będę chciał podnieść lub opuścić roletę. może wy macie pomysł jak ustalać pozycję rolety bo ja nie mogę do tego dojść
To zależy jak masz zbudowany układ sterowania.
Pomagam za darmo więc szanuj mój czas.
Wklejaj tekst a nie jego zdjęcie.
Nie pisz następnego postu jak nie odpowiedziałeś na poprzedni.
Jak mądrze zadawać pytania
 
Odpowiedź
#12
(16-11-2016, 22:22)Ghost1991 napisał(a): czy da się odczytać pozycję rolety gdy np opuścimy ją ręcznie powiedzmy o 1/3 okna.
Coś tam się ta.
Możesz spróbować odczytywać pozycję za pomocą enkodera, a możesz spróbować za pomocą potencjometru wieloobrotowego. Robiłem kiedyś tego typu układ. Co prawda nie użyłem do tego Arduino, ale metoda kontroli pozycji była taka sama.
 
Odpowiedź
#13
Chciałem napisać w poprzednim wątku ale został zamknięty (http://forum.arduinopolska.com/watek-aut...ety?page=2).
Otóż po intensywnym kursie i lekturze o arduino udało mi się coś sklekocić z roletami. Działa to tak:
Dzwoni cichy alarm w Sleep as android (cichy, bo chcę aby rolety otwierały się pół godziny przed właściwym budzikiem) ----> informacja do IFTTT ----> IFTTT wysyła informację "1" do feed'a adafruit -----> NodeMCU v3 odczytuje informację "1" z feed'a ----> NodeMCU v3 uruchamia serwo

Na razie jest tylko odsłanianie zasłon.
Serwo to MG995 przerobione na pracę ciągłą.
Docelowo serwo będzie zasilane osobno, na razie do testów bez obciążenia zasilam z jednego USB.

Chciałbym Was prosić o poradę jak mechanicznym wyłącznikiem krańcowym przerywać pracę serwa?
a) rozwiązać to programowo funkcją if
b) wpiąć krańcówkę w kabel zasilający NodeMCU a kiedy będę wstał z łózka po prostu odłączyć zasilanie
c) inne rozwiązanie

https://drive.google.com/file/d/1m0GHfuA...sp=sharing

Proszę też o sprawdzenie kodu i wskazówki co zrobiłem źle.


Kod:
// Adafruit IO REST API access with ESP8266
//
// For use with ESP8266 Arduino from:
//   https://github.com/esp8266/Arduino
//
// Works great with ESP8266 modules like the Adafruit Huzzah ESP:
//  ----> https://www.adafruit.com/product/2471
//
// Written by Tony DiCola for Adafruit Industries.  
// MIT license, all text above must be included in any redistribution.
#include <ESP8266WiFi.h>
#include "Adafruit_IO_Client.h"
#include <Servo.h>


// Configure WiFi access point details.
#define WLAN_SSID  "xxxxxxx"
#define WLAN_PASS  "xxxxxxxx"

// Configure Adafruit IO access.
#define AIO_KEY    "xxxxxxxxxxxxxxxxxxxxxxx"


// Create an ESP8266 WiFiClient class to connect to the AIO server.
WiFiClient client;

// Create an Adafruit IO Client instance.  Notice that this needs to take a
// WiFiClient object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

// Finally create instances of Adafruit_IO_Feed objects, one per feed.  Do this
// by calling the getFeed function on the Adafruit_IO_FONA object and passing
// it at least the name of the feed, and optionally a specific AIO key to use
// when accessing the feed (the default is to use the key set on the
// Adafruit_IO_Client class).
Adafruit_IO_Feed zaslony = aio.getFeed("zaslony");

// Alternatively to access a feed with a specific key:
//Adafruit_IO_Feed testFeed = aio.getFeed("esptestfeed", "...esptestfeed key...");

// Global state to increment a number and send it to the feed.
unsigned int count = 0;
Servo myservo;
int pos = 94;

void setup() {
 // Setup serial port access.
 Serial.begin(9600);
 delay(10);
 Serial.println(); Serial.println();
 Serial.println(F("Adafruit IO ESP8266 test!"));
 pinMode(2,OUTPUT);
 digitalWrite(2,LOW);
 myservo.attach(2);
 

 // Connect to WiFi access point.
 Serial.print("Connecting to ");
 Serial.println(WLAN_SSID);

 WiFi.begin(WLAN_SSID, WLAN_PASS);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println();

 Serial.println("WiFi connected");  
 Serial.println("IP address: "); Serial.println(WiFi.localIP());
 
 // Initialize the Adafruit IO client class (not strictly necessary with the
 // client class, but good practice).
 aio.begin();

 Serial.println(F("Ready!"));
}

void loop() {

 // To read the latest feed value call the receive function on the feed.
 // The returned object will be a FeedData instance and you can check if it's
 // valid (i.e. was successfully read) by calling isValid(), and then get the
 // value either as a text value, or converted to an int, float, etc.
 FeedData latest = zaslony.receive();
 if (latest.isValid()) {
   Serial.print(F("Received value from feed: ")); Serial.println(latest);
   // By default the received feed data item has a string value, however you
   // can use the following functions to attempt to convert it to a numeric
   // value like an int or float.  Each function returns a boolean that indicates
   // if the conversion succeeded, and takes as a parameter by reference the
   // output value.
   int i;
   if (latest.intValue(&i)) {
     Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
   }
   // Other functions that you can use include:
   //  latest.uintValue() (unsigned int)
   //  latest.longValue() (long)
   //  latest.ulongValue() (unsigned long)
   //  latest.floatValue() (float)
   //  latest.doubleValue() (double)
   if (i == 1){
     Serial.println("Alarm on!");
     for (pos = 96; pos <= 180; pos += 1)
     myservo.write(pos);
     delay(1000);
   }
   else{
     digitalWrite(2,LOW);
   }
   }
 else{
   Serial.print(F("Failed to receive the latest feed value!"));
   digitalWrite(2,LOW);
 }
 // Now wait 10 more seconds and repeat.
 Serial.println(F("Waiting 10 seconds and then writing a new feed value."));
 delay(10000);
}
 
Odpowiedź
#14
Witam,
Obsłużyć krańcówkę za pomocą przerwania,
Pozdrawiam,
Tomek.
 
Odpowiedź
#15
Dzięki próbowałem "break" ale nie umiem tego ogarnąć moglibyście pomóc? Wszystkie sposoby w jakie próbowałem zatrzymać serwo wyłącznikiem krańcowym działają z bardzo dużym opóźnieniem. A zasłona powinna zatrzymać się natychmiast. Próbowałem ostatnim razem serwo.detach() ale też działa z opóźnieniem.
Kod:
// Adafruit IO REST API access with ESP8266
//
// For use with ESP8266 Arduino from:
//   https://github.com/esp8266/Arduino
//
// Works great with ESP8266 modules like the Adafruit Huzzah ESP:
//  ----> https://www.adafruit.com/product/2471
//
// Written by Tony DiCola for Adafruit Industries.
// MIT license, all text above must be included in any redistribution.
#include <ESP8266WiFi.h>
#include "Adafruit_IO_Client.h"
#include <Servo.h>


// Configure WiFi access point details.
#define WLAN_SSID  "xxxxxx"
#define WLAN_PASS  "xxxxxxxxxxx"

// Configure Adafruit IO access.
#define AIO_KEY    "xxxxxxxxxxxx"


// Create an ESP8266 WiFiClient class to connect to the AIO server.
WiFiClient client;

// Create an Adafruit IO Client instance.  Notice that this needs to take a
// WiFiClient object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

// Finally create instances of Adafruit_IO_Feed objects, one per feed.  Do this
// by calling the getFeed function on the Adafruit_IO_FONA object and passing
// it at least the name of the feed, and optionally a specific AIO key to use
// when accessing the feed (the default is to use the key set on the
// Adafruit_IO_Client class).
Adafruit_IO_Feed zaslony = aio.getFeed("zaslony");

// Alternatively to access a feed with a specific key:
//Adafruit_IO_Feed testFeed = aio.getFeed("esptestfeed", "...esptestfeed key...");

// Global state to increment a number and send it to the feed.
unsigned int count = 0;
Servo myservo;
int pos = 94;
const int buttonPin = 12;
int buttonState = 0;

void setup() {
 // Setup serial port access.
 Serial.begin(9600);
 delay(10);
 Serial.println(); Serial.println();
 Serial.println(F("Adafruit IO ESP8266 test!"));
pinMode(buttonPin, INPUT_PULLUP);
 // Connect to WiFi access point.
 Serial.print("Connecting to ");
 Serial.println(WLAN_SSID);

 WiFi.begin(WLAN_SSID, WLAN_PASS);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println();

 Serial.println("WiFi connected");
 Serial.println("IP address: "); Serial.println(WiFi.localIP());

 // Initialize the Adafruit IO client class (not strictly necessary with the
 // client class, but good practice).
 aio.begin();

 Serial.println(F("Ready!"));
}

void loop() {

 // To read the latest feed value call the receive function on the feed.
 // The returned object will be a FeedData instance and you can check if it's
 // valid (i.e. was successfully read) by calling isValid(), and then get the
 // value either as a text value, or converted to an int, float, etc.
 FeedData latest = zaslony.receive();
 buttonState = digitalRead(buttonPin);
 myservo.attach(2);
 if (latest.isValid()) {
   Serial.print(F("Received value from feed: ")); Serial.println(latest);
   // By default the received feed data item has a string value, however you
   // can use the following functions to attempt to convert it to a numeric
   // value like an int or float.  Each function returns a boolean that indicates
   // if the conversion succeeded, and takes as a parameter by reference the
   // output value.
   int i;
   if (latest.intValue(&i)) {
     Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
   }
   // Other functions that you can use include:
   //  latest.uintValue() (unsigned int)
   //  latest.longValue() (long)
   //  latest.ulongValue() (unsigned long)
   //  latest.floatValue() (float)
   //  latest.doubleValue() (double)
   if (i == 1) {
     Serial.println("Alarm on!");
     for (pos = 94; pos <= 180; pos += 1)
       myservo.write(pos);
     delay(1000);
   }
   else {
     digitalWrite(2, LOW);
   }
 }
   else {
   Serial.print(F("Failed to receive the latest feed value!"));
   digitalWrite(2, LOW);
 }
 if (latest.isValid()) {
   Serial.print(F("Received value from feed: ")); Serial.println(latest);
   // By default the received feed data item has a string value, however you
   // can use the following functions to attempt to convert it to a numeric
   // value like an int or float.  Each function returns a boolean that indicates
   // if the conversion succeeded, and takes as a parameter by reference the
   // output value.
 int i;
 if (latest.intValue(&i)) {
   Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
 }
 // Other functions that you can use include:
 //  latest.uintValue() (unsigned int)
 //  latest.longValue() (long)
 //  latest.ulongValue() (unsigned long)
 //  latest.floatValue() (float)
 //  latest.doubleValue() (double)
 if (i == 2) {
   Serial.println("Alarm on!");
   for (pos = 180; pos >= 94; pos -= 1)
     myservo.write(!pos);
   delay(1000);
 }
 else {
   digitalWrite(2, LOW);
 }
 }
 else {
   Serial.print(F("Failed to receive the latest feed value!"));
   digitalWrite(2, LOW);
 }
 if (buttonState == HIGH) {
   myservo.detach();
 }
else {
}
 if
 // Now wait 10 more seconds and repeat.
 (Serial.println(F("Waiting 10 seconds and then writing a new feed value.")));
 delay(10000);
}

Czy macie jakiś pomysł co zrobić aby stan wyłącznika krańcowego był odczytywany stale, równocześnie z działaniem serwa albo aby pętla przechodziła na tyle szybko aby krańcówka zatrzymywała zasłonę natychmiast. Mógłbym po prostu dać krańcówkę na zasilaniu do serwa, bo prąd nie jest duży ale wolałbym to zrobić programowo zgodnie ze sztuką i przy okazji się czegoś nauczę.
 
Odpowiedź
#16
Usuń delay, naucz się korzystać z przykładu arduino blinkwitheoutdelay i poznaj zastosowanie funkcji millis(). Przykłady z delay to najprostsze programiki użyteczne do obsługi 1 typu czujnika, przy programach wielozadaniowych są bardzo szkodliwe i frustrujące. Uzasadnione użycie delay jest rzadko spotykane. Jeśli naciśniesz przycisk w czasie delay(10000) to zostanie zauważony tylko w przerwaniu, a reakcja i tak będzie jak się skończy ten czas.
Miło być decenianym https://buycoffee.to/kaczakat
 
Odpowiedź
#17
Co się najlepiej będzie nadawać? Bo wyczytałem w tym poście, że można użyć zwykłego silnika z mostkiem H lub serwomechanizm. Jaka będzie różnica? Jakie mają wady i zalety poszczególne rozwiązania?
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości