FHEM Forum

Verschiedenes => Bastelecke => MySensors => Thema gestartet von: PeMue am 28 September 2019, 22:11:45

Titel: MySensors Gateway mit Arduino pro micro
Beitrag von: PeMue am 28 September 2019, 22:11:45
Hallo zusammen,

ich mache für sash.sc eine Platine, siehe hier: https://forum.fhem.de/index.php/topic,103979.msg978843.html#msg978843
Da ich das Ganze etwas universeller gestalten möchte, packe ich noch einen MySensor Chip mit drauf (NRF25L01+, ggf. noch einen RFM69 bzw. 95). Die Platine soll WLAN (mit WeMos D1 mini als serial bridge), LAN und USB können. Für die USB Variante würde ich den Arduino pro micro vorsehen, der hat den Spannungsregler und den USB Kram schon mit drauf.
Meine Frage an die MySensors Spezialisten: Kann man den Sketch auch für Arduino pro micro compilieren, so dass man dessen USB Schnittstelle verwenden kann?

Danke + Gruß

Peter
Titel: Antw:MySensors Gateway mit Arduino pro micro
Beitrag von: Beta-User am 29 September 2019, 08:11:54
Das geht, mein RS485-GW läuft seit langem auf pro micro-Basis, das wird sogar von autocreate/usb scan erkannt ;D . (sollte mit einem auf Maple-Basis auch so sein).

Man sieht nur den sauberen Start nicht, wenn man z.B. mit der Arduino IDE den seriellen Monitor nutzt; das geht zu schnell. Habe daher einen preHwInit()-Abschnitt mit einem kleinen wait eingefügt.

Im Zusammenhang (Achtung, höhere Baudrate@RS485...):
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
* The RS485 Gateway prints data received from sensors on the serial link.
* The gateway accepts input on seral which will be sent out on
* the RS485 link.
*
* Wire connections (OPTIONAL):
* - Inclusion button should be connected between digital pin 3 and GND
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
*
* LEDs (OPTIONAL):
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
*
* If your Arduino board has additional serial ports
* you can use to connect the RS485 module.
* Otherwise, the gateway uses AltSoftSerial to handle two serial
* links on one Arduino. Use the following pins for RS485 link
*
*  Board          Transmit  Receive   PWM Unusable
* -----          --------  -------   ------------
* Teensy 3.0 & 3.1  21        20         22
* Teensy 2.0         9        10       (none)
* Teensy++ 2.0      25         4       26, 27
* Arduino Uno        9         8         10
* Arduino Leonardo   5        13       (none)
* Arduino Mega      46        48       44, 45
* Wiring-S           5         6          4
* Sanguino          13        14         12
*
*/

// Enable debug prints to serial monitor
#define MY_DEBUG
#define MY_SPECIAL_DEBUG

// Enable RS485 transport layer
#define MY_RS485

// Define this to enables DE-pin management on defined pin
//#define MY_RS485_DE_PIN 2

// Set RS485 baud rate to use
#define MY_RS485_BAUD_RATE 19200 //57600 //9600 57600

// Enable this if RS485 is connected to a hardware serial port
//#define MY_SERIALDEVICE Serial
//#define USBCON
#define MY_RS485_HWSERIAL Serial1

// Enable serial gateway
#define MY_GATEWAY_SERIAL
//#define MY_DEBUGDEVICE Serial
//#define MY_SERIALDEVICE Serial2
//#define MY_REPEATER_FEATURE

// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
#define MY_INCLUSION_BUTTON_FEATURE
// 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

// Flash leds on rx/tx/err
#define MY_DEFAULT_ERR_LED_PIN 17  // Error led pin
#define MY_DEFAULT_RX_LED_PIN  30 //5  // Receive led pin
#define MY_DEFAULT_TX_LED_PIN  17 //6  // the PCB, on board LED

#include <MySensors.h>

void preHwInit() {
  wait(500);
}

void setup()
{
  // Setup locally attached sensors
}

void presentation()
{
// Present locally attached sensors
}

void loop()
{
// Send locally attached sensor data here*/
}


Gruß!
Titel: Antw:MySensors Gateway mit Arduino pro micro
Beitrag von: PeMue am 29 September 2019, 11:27:06
vielen Dank, hilft mir sehr weiter.

Gruß Peter