ExWindspeed v0.1.0-beta ExWindspeed View Source
Functions for reading data from a windspeed sensor connected through an MCP3008 analog to digital chip.
Hardware
ExWindspeed was built to support a windspeed sensor purchased from Adafruit, Anemometer Wind Speed Sensor w/Analog Voltage Output. To communicate with the device from a RaspberryPi the signal is required to be digital as there are no analog inputs on the RaspberryPi. Using a MCP3008 analog to digital chip allows communication with up to 8 channels of 10-bit analog input.
Follow the wiring section
Specifics
- Output: 0.4V to 2V
- Testing Range: 0.5m/s to 50m/s
- Start wind speed: 0.2 m/s
- Resolution: 0.1m/s
- Accuracy: Worst case 1 m/s
- Max Wind Speed: 70m/s
Connector details:
- Pin 1 - Power (brown wire)
- Pin 2 - Ground (black wire)
- Pin 3 - Signal (blue wire)
- Pin 4 - Not connected
The Signal wire should be connected to one of the channels
described below.
Wiring
MCP3008 ADC (Analog to Digital Converter)
Channels Connections to PI
____
0 -| |- 3.3V
1 -| |- 3.3V
2 -| |- Ground
3 -| |- Pin 18
4 -| |- Pin 23
5 -| |- Pin 24
6 -| |- Pin 25
7 -|____|- Ground
Configuration
ExWindspeed supports local development by having the sensor implementation configurable. By default the Raspberry PI implementation is used and expects hardware to be connected.
SPI Device
The device to communicate with via SPI can be configured with the device
key.
If the device
key is not configured the default SPI device will be
spidev0.0
.
SPI Transmission Data
Data is transmitted to the SPI device and tells the chip which channel to read
from. The default bitstring will read from channel 0, if you are using another
channel you can set the bitstring to use with the spi_transfer_payload
key.
Local Development
If you wish to use ExWindspeed during local development the
ExWindspeed.Platform.Host.SensorImpl
should be used.
config :ex_windspeed, implementation: ExWindspeed.Platform.Host.SensorImpl
With the configuration shown above, all calls to ExWindspeed.read/0
shall return the same windspeed with the current UTC DateTime for read_at
.
Example Configuration
The defaults are used for this example.
config :ex_windspeed,
implementation: ExWindspeed.Platform.RPI.SensorImpl,
device: "spidev0.0",
spi_transfer_payload: <<0x01, 0x80, 0x00>>
Link to this section Summary
Types
Windspeed in meters per second.
Windspeed in miles per hour.
Date and time in UTC (using local device time) that the data was read from the sensor. If your nerves project doesn't use a means to sync local time this value will be useless.
Struct containing wind speed from the sensor.
Link to this section Types
meters_per_second()
View Source
meters_per_second() :: float()
meters_per_second() :: float()
Windspeed in meters per second.
miles_per_hour()
View Source
miles_per_hour() :: float()
miles_per_hour() :: float()
Windspeed in miles per hour.
read_at()
View Source
read_at() :: DateTime.t()
read_at() :: DateTime.t()
Date and time in UTC (using local device time) that the data was read from the sensor. If your nerves project doesn't use a means to sync local time this value will be useless.
t()
View Source
t() :: %ExWindspeed{
meters_per_second: meters_per_second(),
miles_per_hour: miles_per_hour(),
read_at: read_at()
}
t() :: %ExWindspeed{ meters_per_second: meters_per_second(), miles_per_hour: miles_per_hour(), read_at: read_at() }
Struct containing wind speed from the sensor.
Link to this section Functions
read()
View Source
read() :: {:ok, ExWindspeed.t()} | {:error, ExWindspeed.Error.t()}
read() :: {:ok, ExWindspeed.t()} | {:error, ExWindspeed.Error.t()}
Read current wind speed from sensor