Start z arduino i ESP8266

User avatar
klew
Posts: 8357
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

kimuril wrote: Sun Feb 09, 2020 11:36 am Wszystko w takim razie sie wyjaśniło. Dokupie w takim razie expander portow i sprobuje jeszcze raz podzialac. Dziekie za wszystkie odpowiedzi.
Pamiętaj tylko, że ten ekspander też trzeba sobie zaprogramować. Nie jest to trudne (przynajmniej patrząc po przykładach), ale biblioteka SuplaDevice tego nie ma zaimplementowanego
Widzimy się na Supla Offline Party vol. 2 :!:
elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

ułatwiasz pracę w nowej bibliotece dzięki <IO>. :)
Podstawowy przykład dla 16 dodatkowych wyjść z McP23017.

Code: Select all

/*
Copyright (C) AC SOFTWARE SP. Z O.O.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <SPI.h>
#include <SuplaDevice.h>
#include <io.h>
#include <Adafruit_MCP23017.h>

/*
 * This example requires Dallas Temperature Control library installed. 
 * https://github.com/milesburton/Arduino-Temperature-Control-Library
 */


// Choose proper network interface for your card:
// Arduino Mega with EthernetShield W5100:
// #include <supla/network/ethernet_shield.h>
// Ethernet MAC address
// uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
// Supla::EthernetShield ethernet(mac);
//
// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// Supla::ENC28J60 ethernet(mac);
//
// ESP8266 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("your_wifi_ssid", "your_wifi_password");
//
// ESP32 based board:
// #include <supla/network/esp32_wifi.h>
// Supla::ESP32Wifi wifi("your_wifi_ssid", "your_wifi_password");

Adafruit_MCP23017 mcp;

class MyMcp23017 : public Supla::Io {
  public:
    void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) {
      if ((pin >= 100)&& (pin <= 115)){
        mcp.digitalWrite(pin - 100, val);  
         return;
      }
      if (pin <= 99) {
        return ::digitalWrite(pin,val);  
      }
   }
   
   int customDigitalRead(int channelNumber, uint8_t pin) {
      if ((pin >= 100)&& (pin <= 115)){
        return mcp.digitalRead(pin - 100);     
      }     
      if (pin <= 99){
        return ::digitalRead(pin);  
      }
    }   
}MyMcp23017; 

void setup() {

  Serial.begin(115200);

   mcp.begin(); 
   
  mcp.pinMode(0, OUTPUT);
  mcp.pinMode(1, OUTPUT);
  mcp.pinMode(2, OUTPUT);
  mcp.pinMode(3, OUTPUT);
  mcp.pinMode(4, OUTPUT);
  mcp.pinMode(5, OUTPUT);
  mcp.pinMode(6, OUTPUT);
  mcp.pinMode(7, OUTPUT);
  mcp.pinMode(8, OUTPUT);
  mcp.pinMode(9, OUTPUT);
  mcp.pinMode(10, OUTPUT);
  mcp.pinMode(11, OUTPUT);
  mcp.pinMode(12, OUTPUT);
  mcp.pinMode(13, OUTPUT);
  mcp.pinMode(14, OUTPUT);
  mcp.pinMode(15, OUTPUT); 

  // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

  // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

  /*
   * 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.addRelay(100, false);
      SuplaDevice.addRelay(101, false); 
      SuplaDevice.addRelay(102, false); 
      SuplaDevice.addRelay(103, false); 
      SuplaDevice.addRelay(104, false); 
      SuplaDevice.addRelay(105, false); 
      SuplaDevice.addRelay(106, false);
      SuplaDevice.addRelay(107, false);
      SuplaDevice.addRelay(108, false);
      SuplaDevice.addRelay(109, false); 
      SuplaDevice.addRelay(110, false); 
      SuplaDevice.addRelay(111, false); 
      SuplaDevice.addRelay(112, false); 
      SuplaDevice.addRelay(113, false); 
      SuplaDevice.addRelay(114, false);
      SuplaDevice.addRelay(115, false); 


  // CHANNEL3 - TWO RELAYS (Roller shutter operation)
  SuplaDevice.addRollerShutterRelays(46,     // 46 - Pin number where the 1st relay is connected   
                                     47, true);    // 47 - Pin number where the 2nd relay is connected  

  // CHANNEL4 - Opening sensor (Normal Open)
  SuplaDevice.addSensorNO(5); // 5 - Pin number where the sensor is connected
                               // Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
                               // to enable the internal pull-up resistor


  // CHANNEL5 - Opening sensor (Normal Open)
  SuplaDevice.addSensorNO(6); // 6 - Pin number where the sensor is connected


 

  /*
   * SuplaDevice Initialization.
   * Server address, LocationID and LocationPassword are available at https://cloud.supla.org 
   * If you do not have an account, you can create it at https://cloud.supla.org/account/create
   * SUPLA and SUPLA CLOUD are free of charge
   * 
   */

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    "svr1.supla.org",  // SUPLA server address
                    "email@address",   // Email address used to login to Supla Cloud
                    AUTHKEY);          // Authorization key
    
}

void loop() {
  SuplaDevice.iterate();
}
piomar2
Posts: 369
Joined: Fri Apr 26, 2019 5:32 pm
Location: Bukowice

Post

Witaj GURU!

Ja już po szpitalu (masakra) i na szczęście jest SUPLA i tacy ludzie jak Ty. Dajecie mi tyle radości i możliwości poznawania nowych rozwiązań. Wczoraj przeczytałem na forum o ekspanderze McP23017 i bardzo mnie to zaciekawiło, i od razu złożyłem zamówienie "u przyjaciół". Dzisiaj ad rana niespodzianka, bo Dajesz gotowe rozwiązanie. Kod pięknie się skompilował i czekam tylko na ekspandery do testów.
Twoja pomoc jest SUPER... :D

Pozdrawiam
User avatar
Dawid84
Posts: 154
Joined: Mon Jan 14, 2019 12:45 pm
Location: Piekary Śląskie

Post

Pytanie jakie ustawienia maja byc w programie arduino ide tzn jaką płytkę wybrac z listy dla wemos d1 mini, NodeMCU bo próbuje i wywala mi blad ze plytka wybrana nie taka jak trzeba, port com mam prawidlowy, do tej pory wszystko co potrzebowalem wgrywać to byly binarki i wgrywalem esptool i bylo ok.
Czy jest wogóle jakis lopatologiczny opis jak to zrobic co dodac, wybrać zeby dalo sie wgrac.

Sorry moze głupie pytanie ale temat programowania i arduino dopiero próbuję ogarnąć.
Pozdrawiam
Dawid
piomar2
Posts: 369
Joined: Fri Apr 26, 2019 5:32 pm
Location: Bukowice

Post

Tak ustaw dla Wemosa mini:

Wemos_mini.png
a tak dla Node:

NodeMcu.PNG
You do not have the required permissions to view the files attached to this post.
User avatar
Dawid84
Posts: 154
Joined: Mon Jan 14, 2019 12:45 pm
Location: Piekary Śląskie

Post

Dziś miałem trochę czasu i postanowiłem sprawdzić czy będzie działać ale niestety lipa wywala mi taki błąd jak na zdjęciu i tam też jakie ustawienia mam.
Dodam że arduino nie jest moją mocną stroną dopiero zaczynam się tym bawić.
You do not have the required permissions to view the files attached to this post.
Pozdrawiam
Dawid
User avatar
wojtas567
Posts: 2214
Joined: Sun Apr 03, 2016 7:16 pm
Location: Olsztyn

Post

A zobacz czy jak wybierzesz płytkę generic ESP8266 to czy uda Ci się skompilować ten skecz?
Pozdrawiam
Wojtek
User avatar
Dawid84
Posts: 154
Joined: Mon Jan 14, 2019 12:45 pm
Location: Piekary Śląskie

Post

W końcu miałem chwilę żeby sprawdzić czy da się wgrać ale niestety nic z tego nie wyszło.
You do not have the required permissions to view the files attached to this post.
Pozdrawiam
Dawid
User avatar
QLQ
Posts: 2279
Joined: Sun Sep 03, 2017 9:13 am
Location: Koszalin

Post

Jak wywala taki błąd - nie ma możliwości wgrania wybierając dowolną płytkę z ESP8266 to przede wszystkim sprawdź tę ścieżkę - mam wersję płytek 2.5.0 więc mam:
.
Clip_2.jpg
.
w katalogu ESP8266 ma być tylko jeden katalog z wersją płytek - np 2.5.0 . Jak będzie tych katalogów więcej to będzie taki błąd wywalał
You do not have the required permissions to view the files attached to this post.
jak coś nie działa to włącz zasilanie.....
radzik_r
Posts: 394
Joined: Sun Aug 11, 2019 5:32 pm

Post

Co to jest to:

Code: Select all

#include <io.h>
wyskakuje mi taki błąd przy próbie kompilacji tego softu z przykładem Mcp23017

Code: Select all


sketch_nov02b:19:16: fatal error: io.h: No such file or directory
 #include <io.h>
                ^
compilation terminated.
exit status 1
io.h: No such file or directory

Return to “Arduino IDE”