Mysensor usb gateway serial problem



  • Hello, could somebody help me and say why it doesn't work?

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    
    // Enable and select radio type attached
    //#define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level.
    #define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <MySensors.h>
    
    #define CHILD_ID 3
    #define BUTTON_PIN  3 
    
    #define RELAY_PIN 4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    
    void before()
    {
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    int gate = 23;   
    int relay1 =  22; 
    
    
    void setup()
    {
      Serial.begin (115200);
        pinMode(BUTTON_PIN,INPUT);
        digitalWrite(BUTTON_PIN,HIGH);
      
        pinMode(relay1, OUTPUT);
        digitalWrite (relay1, LOW);
        pinMode(gate, OUTPUT);
        digitalWrite (gate, LOW);
        pinMode(24, INPUT_PULLUP);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay", "1.0");
    
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
      }
    }
    
    
    void loop()
    {
       byte value = analogRead(0);
     if (value == LOW){
      delay(10); 
      digitalWrite(gate, LOW);
     digitalWrite(relay1, LOW);
     delay(2000); 
     digitalWrite(gate, HIGH);
      } 
      
      if (value == HIGH){
      delay(10);
      digitalWrite(gate, LOW);
     digitalWrite(relay1, HIGH);
      delay(2000); 
      digitalWrite(gate, HIGH);
    
      }
    
    }
    
    void receive(const MyMessage &message)
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_STATUS) {
        // Change relay state
        digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
        // Store state in eeprom
        saveState(message.sensor, message.getBool());
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

  • Mod

    Welcome to the MySensors community @dany17

    Would you mind sharing what you mean by "it" and "doesn't work"?

    If you haven't already, see https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/ for the most common problems and how to troubleshoot them efficiently.


  • Hardware Contributor

    @dany17
    Hi.
    My crystal ball 🙂 told me you need to uncomment this line in your sketch if you're planning to use nrf24 :

    //#define MY_RADIO_RF24
    to
    #define MY_RADIO_RF24
    

    If it doesn't help, like mfalkvidd said please show us your debug logs.



  • @scalz said in Mysensor usb gateway serial problem:

    If it doesn't help, like mfalkvidd said please show us your debug logs.

    OK i do //#define MY_RADIO_RF24 because for now I wanted to make a base station via usb

    I will tell you my idea and you will tell if it is possible here because I am slowly losing faith XD
    I want to use mega2560 to control several devices. One of them is the roller blind that I converted into electric motor control (currently I have two. The first classic 2 wires and I have connected to 3 contactors which control the direction and time of operation. The second stepper motor).
    I now want to use my sensor to control the blind in domoticz with 1 switch or if it could be slider.

    The next thing would be INA219 but maybe later for the time being on this roller blind, is it possible to do?



  • I would like to use this program in mysensors with a switch from domoticz

    #include <Stepper.h>
    #define STEPS 32 
    Stepper stepper (STEPS, 8, 10, 9, 11); 
    int val = 0;
    
    void setup () { 
      Serial.begin (9600);
     stepper.setSpeed (800); 
      pinMode(4, INPUT_PULLUP); 
    
    }
    
    void loop () {
      if (digitalRead (4) == LOW) 
      { 
        val = 20480; 
        stepper.step (val); 
        Serial.println (val); 
      }
      
     if (digitalRead (4) == HIGH) 
      {
        val = -20480; 
        stepper.step (val); 
        Serial.println (val); 
    }
    }
    


  • @dany17
    If you want to use arduino connected via usb to computer and your sensors connected to that arduino with MySensors, I recommend starting with sketch "GatewaySerialRS485" from MySensors examples and present your sensors in this sketch.
    But honestly, I don't think you have enough experience for this task yet.
    For example:

    byte value = analogRead(0);
     if (value == LOW){
      delay(10); 
      digitalWrite(gate, LOW);
     digitalWrite(relay1, LOW);
     delay(2000); 
     digitalWrite(gate, HIGH);
      } 
      
      if (value == HIGH){
      delay(10);
      digitalWrite(gate, LOW);
     digitalWrite(relay1, HIGH);
      delay(2000); 
      digitalWrite(gate, HIGH);
    

    You compare analog readed value if it matches the exact value?
    In how many cases does this occur?
    And you know the value of the definition values LOW and HIGH in Arduino?



  • @kimot
    yes I know this is an error but I wanted to read the value from pin 4. this example worked for me (RelayActuator) I wanted to use this ordinary switch to control the rest of the program. that's all I need at the moment


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 1
  • 3
  • 5
  • 6

7
Online

11.4k
Users

11.1k
Topics

112.7k
Posts