Add valve example
Used for gardena valves with 9V power supply.
This commit is contained in:
parent
c56142ccec
commit
dca85a7b6b
58
examples/osd/arduino-valve/Makefile
Normal file
58
examples/osd/arduino-valve/Makefile
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# Set this to the name of your sketch (without extension .pde)
|
||||||
|
SKETCH=sketch
|
||||||
|
EXE=arduino-example
|
||||||
|
|
||||||
|
all: $(EXE)
|
||||||
|
|
||||||
|
CONTIKI=../../..
|
||||||
|
|
||||||
|
# Contiki IPv6 configuration
|
||||||
|
CONTIKI_WITH_IPV6 = 1
|
||||||
|
|
||||||
|
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||||
|
|
||||||
|
PROJECT_SOURCEFILES += resource_valve.c ${SKETCH}.cpp
|
||||||
|
|
||||||
|
# variable for Makefile.include
|
||||||
|
ifneq ($(TARGET), minimal-net)
|
||||||
|
CFLAGS += -DUIP_CONF_IPV6_RPL=1
|
||||||
|
else
|
||||||
|
# minimal-net does not support RPL under Linux and is mostly used to test CoAP only
|
||||||
|
${info INFO: compiling without RPL}
|
||||||
|
CFLAGS += -DUIP_CONF_IPV6_RPL=0
|
||||||
|
CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\"
|
||||||
|
${info INFO: compiling with large buffers}
|
||||||
|
CFLAGS += -DUIP_CONF_BUFFER_SIZE=2048
|
||||||
|
CFLAGS += -DREST_MAX_CHUNK_SIZE=1024
|
||||||
|
CFLAGS += -DCOAP_MAX_HEADER_SIZE=640
|
||||||
|
endif
|
||||||
|
|
||||||
|
# linker optimizations
|
||||||
|
SMALL=1
|
||||||
|
|
||||||
|
# REST Engine shall use Erbium CoAP implementation
|
||||||
|
APPS += er-coap
|
||||||
|
APPS += rest-engine
|
||||||
|
APPS += time json arduino json-resource
|
||||||
|
|
||||||
|
include $(CONTIKI)/Makefile.include
|
||||||
|
include $(CONTIKI)/apps/arduino/Makefile.include
|
||||||
|
|
||||||
|
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
||||||
|
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
||||||
|
|
||||||
|
connect-router: $(CONTIKI)/tools/tunslip6
|
||||||
|
sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64
|
||||||
|
|
||||||
|
connect-router-cooja: $(CONTIKI)/tools/tunslip6
|
||||||
|
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 aaaa::1/64
|
||||||
|
|
||||||
|
connect-minimal:
|
||||||
|
sudo ip address add fdfd::1/64 dev tap0
|
||||||
|
|
||||||
|
avr-size: $(EXE).$(TARGET).sz
|
||||||
|
|
||||||
|
flash: $(EXE).$(TARGET).u # $(EXE).$(TARGET).eu
|
||||||
|
|
||||||
|
.PHONY: flash avr-size
|
||||||
|
.PRECIOUS: $(EXE).$(TARGET).hex $(EXE).$(TARGET).eep
|
23
examples/osd/arduino-valve/README.md
Normal file
23
examples/osd/arduino-valve/README.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
Arduino valve
|
||||||
|
=============
|
||||||
|
|
||||||
|
This is an example how to open/close a Gardena Water-Valve (the ones
|
||||||
|
that use a +9V block battery for power).
|
||||||
|
Note that we used the L293D Dual H-Bridge circuit which needs +5V for
|
||||||
|
power supply (while the Merkur-Board uses 3.3V) but it can use 3.3V
|
||||||
|
inputs directly from the Merkur-Board without a level shifter. So it's
|
||||||
|
probably a good idea to use some other H-Bridge circuit that can also
|
||||||
|
use 3.3V. An advantage of the L293D might be that it can be used for two
|
||||||
|
valves simultaneously (with the second, currently unused H-Bridge).
|
||||||
|
|
||||||
|
We provide the schematics of our breadboard-design in
|
||||||
|
valve-breadboard.png -- as noted above it's a good idea to use a
|
||||||
|
different H-Bridge circuit.
|
||||||
|
|
||||||
|
Also note that one of the pins we use in the software for signals to the
|
||||||
|
H-Bridge (D4) is also used for the LED on the Merkurboard. The LED is
|
||||||
|
*on* when the H-Bridge is *off*. This was nice for testing the
|
||||||
|
breadboard circuit but should be changed for a real deployment to save
|
||||||
|
power of the battery. It is also probably a good idea to turn off the
|
||||||
|
power-supply of the H-Bridge with an additional MOSFET depending on the
|
||||||
|
power consumption of the H-Bridge you're going to use.
|
2
examples/osd/arduino-valve/arduino-example.c
Normal file
2
examples/osd/arduino-valve/arduino-example.c
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include <arduino-process.h>
|
||||||
|
AUTOSTART_PROCESSES(&arduino_sketch);
|
2
examples/osd/arduino-valve/flash.sh
Executable file
2
examples/osd/arduino-valve/flash.sh
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/bash
|
||||||
|
make TARGET=osd-merkur-128 flash
|
101
examples/osd/arduino-valve/project-conf.h
Normal file
101
examples/osd/arduino-valve/project-conf.h
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PROJECT_RPL_WEB_CONF_H_
|
||||||
|
#define PROJECT_RPL_WEB_CONF_H_
|
||||||
|
|
||||||
|
#define PLATFORM_HAS_LEDS 1
|
||||||
|
//#define PLATFORM_HAS_BUTTON 1
|
||||||
|
#define PLATFORM_HAS_BATTERY 1
|
||||||
|
|
||||||
|
#define SICSLOWPAN_CONF_FRAG 1
|
||||||
|
|
||||||
|
/* For Debug: Dont allow MCU sleeping between channel checks */
|
||||||
|
#undef RDC_CONF_MCU_SLEEP
|
||||||
|
#define RDC_CONF_MCU_SLEEP 0
|
||||||
|
|
||||||
|
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
||||||
|
/* For projects, optimize memory and enable RDC again. */
|
||||||
|
// #undef NETSTACK_CONF_RDC
|
||||||
|
//#define NETSTACK_CONF_RDC nullrdc_driver
|
||||||
|
|
||||||
|
/* Increase rpl-border-router IP-buffer when using more than 64. */
|
||||||
|
#undef REST_MAX_CHUNK_SIZE
|
||||||
|
#define REST_MAX_CHUNK_SIZE 64
|
||||||
|
|
||||||
|
/* Estimate your header size, especially when using Proxy-Uri. */
|
||||||
|
/*
|
||||||
|
#undef COAP_MAX_HEADER_SIZE
|
||||||
|
#define COAP_MAX_HEADER_SIZE 70
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The IP buffer size must fit all other hops, in particular the border router. */
|
||||||
|
|
||||||
|
#undef UIP_CONF_BUFFER_SIZE
|
||||||
|
#define UIP_CONF_BUFFER_SIZE 256
|
||||||
|
|
||||||
|
|
||||||
|
/* Multiplies with chunk size, be aware of memory constraints. */
|
||||||
|
#undef COAP_MAX_OPEN_TRANSACTIONS
|
||||||
|
#define COAP_MAX_OPEN_TRANSACTIONS 4
|
||||||
|
|
||||||
|
/* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
|
||||||
|
/*
|
||||||
|
#undef COAP_MAX_OBSERVERS
|
||||||
|
#define COAP_MAX_OBSERVERS 2
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Filtering .well-known/core per query can be disabled to save space. */
|
||||||
|
/*
|
||||||
|
#undef COAP_LINK_FORMAT_FILTERING
|
||||||
|
#define COAP_LINK_FORMAT_FILTERING 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Save some memory for the sky platform. */
|
||||||
|
/*
|
||||||
|
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
|
||||||
|
#define NBR_TABLE_CONF_MAX_NEIGHBORS 10
|
||||||
|
#undef UIP_CONF_MAX_ROUTES
|
||||||
|
#define UIP_CONF_MAX_ROUTES 10
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Reduce 802.15.4 frame queue to save RAM. */
|
||||||
|
/*
|
||||||
|
#undef QUEUEBUF_CONF_NUM
|
||||||
|
#define QUEUEBUF_CONF_NUM 4
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#undef SICSLOWPAN_CONF_FRAG
|
||||||
|
#define SICSLOWPAN_CONF_FRAG 1
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* PROJECT_RPL_WEB_CONF_H_ */
|
69
examples/osd/arduino-valve/resource_valve.c
Normal file
69
examples/osd/arduino-valve/resource_valve.c
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Resource for Arduino PWM
|
||||||
|
* \author
|
||||||
|
* Ralf Schlatterbeck <rsc@runtux.com>
|
||||||
|
*
|
||||||
|
* \brief get/put pwm and period for LED pin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "jsonparse.h"
|
||||||
|
#include "er-coap.h"
|
||||||
|
#include "generic_resource.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "valve.h"
|
||||||
|
|
||||||
|
uint8_t valve;
|
||||||
|
|
||||||
|
int valve_from_string (const char *name, const char *uri, const char *s)
|
||||||
|
{
|
||||||
|
uint32_t tmp = strtoul (s, NULL, 10);
|
||||||
|
if (tmp) {
|
||||||
|
tmp = 1;
|
||||||
|
}
|
||||||
|
if (tmp != valve) {
|
||||||
|
digitalWrite (ENABLE_PIN, HIGH);
|
||||||
|
if (tmp) {
|
||||||
|
digitalWrite (BRIDGE1_PIN, HIGH);
|
||||||
|
digitalWrite (BRIDGE2_PIN, LOW);
|
||||||
|
clock_delay_msec (250);
|
||||||
|
//clock_delay_msec (2500);
|
||||||
|
digitalWrite (BRIDGE1_PIN, LOW);
|
||||||
|
digitalWrite (ENABLE_PIN, LOW);
|
||||||
|
} else {
|
||||||
|
digitalWrite (BRIDGE1_PIN, LOW);
|
||||||
|
digitalWrite (BRIDGE2_PIN, HIGH);
|
||||||
|
clock_delay_msec (62);
|
||||||
|
//clock_delay_msec (2500);
|
||||||
|
digitalWrite (BRIDGE2_PIN, LOW);
|
||||||
|
digitalWrite (ENABLE_PIN, LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
valve = tmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
valve_to_string (const char *name, const char *uri, char *buf, size_t bufsize)
|
||||||
|
{
|
||||||
|
return snprintf (buf, bufsize, "%d", valve);
|
||||||
|
}
|
||||||
|
|
||||||
|
GENERIC_RESOURCE \
|
||||||
|
( valve
|
||||||
|
, VALVE
|
||||||
|
, valve-status
|
||||||
|
, 0
|
||||||
|
, valve_from_string
|
||||||
|
, valve_to_string
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* VI settings, see coding style
|
||||||
|
* ex:ts=8:et:sw=4
|
||||||
|
*/
|
5
examples/osd/arduino-valve/run.sh
Executable file
5
examples/osd/arduino-valve/run.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# For the ages-old bootloader (before 2014) you want to use
|
||||||
|
# BOOTLOADER_GET_MAC=0x0001f3a0 as parameter to make below.
|
||||||
|
make clean TARGET=osd-merkur-128
|
||||||
|
make TARGET=osd-merkur-128
|
34
examples/osd/arduino-valve/sketch.pde
Normal file
34
examples/osd/arduino-valve/sketch.pde
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Gardena 9V Magnet-Valve
|
||||||
|
* We have a CoAP Resource for the Valve, it can be in state 1 (on) and
|
||||||
|
* 0 (off).
|
||||||
|
* Transition on-off outputs a negative pulse
|
||||||
|
* Transition off-on outputs a positive pulse
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "valve.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup (void)
|
||||||
|
{
|
||||||
|
arduino_pwm_timer_init ();
|
||||||
|
digitalWrite (ENABLE_PIN, LOW);
|
||||||
|
digitalWrite (BRIDGE1_PIN, LOW);
|
||||||
|
digitalWrite (BRIDGE2_PIN, LOW);
|
||||||
|
pinMode (ENABLE_PIN, OUTPUT);
|
||||||
|
pinMode (BRIDGE1_PIN, OUTPUT);
|
||||||
|
pinMode (BRIDGE2_PIN, OUTPUT);
|
||||||
|
digitalWrite (ENABLE_PIN, LOW);
|
||||||
|
digitalWrite (BRIDGE1_PIN, LOW);
|
||||||
|
digitalWrite (BRIDGE2_PIN, LOW);
|
||||||
|
|
||||||
|
rest_init_engine ();
|
||||||
|
rest_activate_resource (&res_valve, "valve");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop (void)
|
||||||
|
{
|
||||||
|
printf ("valve : %u\n", valve);
|
||||||
|
}
|
BIN
examples/osd/arduino-valve/valve-breadboard.png
Normal file
BIN
examples/osd/arduino-valve/valve-breadboard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1 MiB |
31
examples/osd/arduino-valve/valve.h
Normal file
31
examples/osd/arduino-valve/valve.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* \defgroup Magnetic Valve
|
||||||
|
*
|
||||||
|
* Resource definition for Magnetic valve
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Resource definitions for the Magnetic valve
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Ralf Schlatterbeck <rsc@tux.runtux.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef valve_h
|
||||||
|
#define valve_h
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "contiki-net.h"
|
||||||
|
#include "er-coap.h"
|
||||||
|
|
||||||
|
#define ENABLE_PIN 2
|
||||||
|
#define BRIDGE1_PIN 3
|
||||||
|
#define BRIDGE2_PIN 4
|
||||||
|
|
||||||
|
extern uint8_t valve;
|
||||||
|
extern resource_t res_valve;
|
||||||
|
|
||||||
|
#endif // valve_h
|
||||||
|
/** @} */
|
Loading…
Reference in a new issue