Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for UART control mode for a02yyuw distance sensor #976

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c2c3830
adding ITemperatureSensor and new method of calibration
jamieboyd Feb 22, 2024
61af8ce
added code for UART Control mode plus datasheets
jamieboyd May 9, 2024
eef9209
Changes upstream, where did they come from
jamieboyd May 9, 2024
a07eda0
merging
jamieboyd May 10, 2024
6ed899f
fixed small bug in serial initialization
jamieboyd May 10, 2024
88f3183
Merge branch 'WildernessLabs:develop' into develop
jamieboyd May 16, 2024
ebe5356
DO meter
jamieboyd May 17, 2024
0097b9a
DO meter
jamieboyd May 17, 2024
f98bdc3
added updating to Thermistor
jamieboyd May 17, 2024
94cf438
added updating to Thermistor
jamieboyd May 17, 2024
a9ded85
Merge branch 'WildernessLabs:develop' into develop
jamieboyd May 22, 2024
84d336a
Updating stuff
jamieboyd May 22, 2024
605dc65
Updating Conditions
jamieboyd May 22, 2024
c72a264
Updating Conditions
jamieboyd May 22, 2024
9c365bc
Updating Conditions
jamieboyd May 22, 2024
ed5dd86
Updating
jamieboyd May 22, 2024
fa3db48
Updating
jamieboyd May 22, 2024
64ba5fa
added thermistor
jamieboyd May 22, 2024
1274def
Added thermistor
jamieboyd May 22, 2024
0044e06
Merge branch 'develop' of https://github.com/jamieboyd/Meadow.Foundat…
jamieboyd May 22, 2024
87b18d1
updating git ignore, stop tracking .csproj and .sln
jamieboyd May 22, 2024
61fd107
More changes to updating
jamieboyd May 23, 2024
5cf3a11
More changes to updating
jamieboyd May 23, 2024
cd4cf70
More changes to updating
jamieboyd May 23, 2024
37661d4
updating
jamieboyd May 23, 2024
6dd01e1
updating
jamieboyd May 23, 2024
b7ecf22
updating
jamieboyd May 23, 2024
8984d38
Delete Source/WaterPlantir directory
jamieboyd May 23, 2024
8b726f7
Merge branch 'WildernessLabs:develop' into develop
jamieboyd May 23, 2024
fb85e88
DO sensor improvements
jamieboyd May 27, 2024
1f351b2
Merge branch 'WildernessLabs:develop' into develop
jamieboyd May 28, 2024
4f50932
Thermistor explorations
jamieboyd May 30, 2024
82eec3b
Merge branch 'develop' of https://github.com/jamieboyd/Meadow.Foundat…
jamieboyd May 30, 2024
63fa1cf
Merge branch 'WildernessLabs:develop' into develop
jamieboyd May 30, 2024
8d5c057
Interfaces
jamieboyd May 31, 2024
bb34957
Merge branch 'develop' of https://github.com/jamieboyd/Meadow.Foundat…
jamieboyd May 31, 2024
8588521
More Interface and update stuff
jamieboyd May 31, 2024
8fdcd34
Merge branch 'WildernessLabs:develop' into develop
jamieboyd May 31, 2024
e4d8405
Merge branch 'WildernessLabs:develop' into develop
jamieboyd May 31, 2024
05eaf65
A02 with UART controlled output mode
jamieboyd Jun 5, 2024
2485223
DO meter updates
jamieboyd Jun 5, 2024
574cc39
Merge branch 'develop' of https://github.com/jamieboyd/Meadow.Foundat…
jamieboyd Jun 5, 2024
9ebb74f
Merge branch 'WildernessLabs:develop' into develop
jamieboyd Jun 5, 2024
71a916a
A02 distance sensor rewriting
jamieboyd Jun 6, 2024
3030188
Merge branch 'WildernessLabs:develop' into develop
jamieboyd Jun 17, 2024
b674bc2
DO sensor code and docs
jamieboyd Jun 17, 2024
1159560
Merge branch 'develop' of https://github.com/jamieboyd/Meadow.Foundat…
jamieboyd Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ namespace Meadow.Foundation.Sensors.Distance
/// </summary>
public class A02yyuw : PollingSensorBase<Length>, IRangeFinder, ISleepAwarePeripheral, IDisposable
{

/// <summary>
/// Constant for output mode UART Auto
/// </summary>
public const byte MODE_UART_AUTO = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both const values are set to the same value of 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the second constant = 2.

/// <summary>
/// Constant for output mode UART Control
/// </summary>
public const byte MODE_UART_CONTROL = 1;
/// <summary>
/// Distance from sensor to object
/// </summary>
Expand All @@ -37,6 +46,11 @@ public class A02yyuw : PollingSensorBase<Length>, IRangeFinder, ISleepAwarePerip
int serialDataBytesRead = 0;
byte serialDataFirstByte;

// Output buffer
private byte[] sendBufer = { 0 };

private byte outPutMode;

private TaskCompletionSource<Length>? dataReceivedTaskCompletionSource;

private readonly bool createdPort = false;
Expand All @@ -48,8 +62,9 @@ public class A02yyuw : PollingSensorBase<Length>, IRangeFinder, ISleepAwarePerip
/// </summary>
/// <param name="device">The device connected to the sensor</param>
/// <param name="serialPortName">The serial port</param>
public A02yyuw(IMeadowDevice device, SerialPortName serialPortName)
: this(device.CreateSerialPort(serialPortName, portSpeed))
/// <param name="outPutModeParam">Output mode of the distance sensor, default is AUTO</param>
public A02yyuw(IMeadowDevice device, SerialPortName serialPortName, byte outPutModeParam = MODE_UART_AUTO)
: this(device.CreateSerialPort(serialPortName, portSpeed, outPutModeParam))
{
createdPort = true;
}
Expand All @@ -58,11 +73,14 @@ public A02yyuw(IMeadowDevice device, SerialPortName serialPortName)
/// Creates a new A02YYUW object communicating over serial
/// </summary>
/// <param name="serialMessage">The serial message port</param>
public A02yyuw(ISerialPort serialMessage)
/// <param name="outPutModeParam">Output mode of the distance sensor, default is AUTO</param>

public A02yyuw(ISerialPort serialMessage, byte outPutModeParam = MODE_UART_AUTO)
{
serialPort = serialMessage;
serialPort.ReadTimeout = TimeSpan.FromSeconds(5);
serialPort.DataReceived += SerialPortDataReceived;
outPutMode = outPutModeParam;
}

/// <summary>
Expand Down Expand Up @@ -125,7 +143,11 @@ private async Task<Length> ReadSingleValue()
{
serialPort.Open();
}

// in UART Control Mode, send a 0 value over serial to toggle the control line
if (outPutMode == MODE_UART_CONTROL)
{
serialPort.Write(sendBufer);
}
var timeOutTask = Task.Delay(SensorReadTimeOut);

await Task.WhenAny(dataReceivedTaskCompletionSource.Task, timeOutTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

**A02yyuw serial ultrasonic distance sensor**

The **A02yyuw** library is included in the **Meadow.Foundation.Sensors.Distance.A02yyuw** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform.
### Pinout for Sensor:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These readme files are auto-generated but I'll grab this text and add it to our docs - thx!

1. (red) VCC power input 3- 5 V
2. (black) ground
3. (yellow) Rx pin function depends on output mode
4. (white) Tx pin function depends on output mode

This driver is part of the [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/) peripherals library, an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT applications.
The A02 series supports 5 different modes of operation (PWM output, UART Controlled output,UART Auto output, Switched output).
The Rx and Tx pin function corresponds to the output mode selected before ordering, and can not be changed. The **A02yyuw** library supports the
UART Controlled output and UART Auto output of the A02, which can be selected in software.

For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/).
In UART Auto mode, when the Rx pin is held low, the module outputs real-time values on the Tx pin with a response time of 100ms.
When pin(RX)is held high, the module outputs processed values, and the data is more stable. The response time is 100~500ms. The **A02yyuw** library
keeps Rx high in UART Auto output, so processed values are obtained.

To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/).
In UART Controlled mode, the module wil perform a distance detection and send data on the Tx pin after the Rx pin receives a falling edge pulse.
The period between Rx pulses must be greater than 70ms. The **A02yyuw** library sends a pulse by writing a byte of data to the serial port.

The **A02yyuw** library is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform and is part of [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/).

The **Meadow.Foundation** peripherals library is an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT application.

## Installation
For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/).

You can install the library from within Visual studio using the the NuGet Package Manager or from the command line using the .NET CLI:
To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/).

`dotnet add package Meadow.Foundation.Sensors.Distance.A02yyuw`
## Usage

```csharp
Expand Down Expand Up @@ -73,20 +85,3 @@ private void A02yyuw_DistanceUpdated(object sender, IChangeResult<Length> e)
## Need Help?

If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/).
## About Meadow

Meadow is a complete, IoT platform with defense-grade security that runs full .NET applications on embeddable microcontrollers and Linux single-board computers including Raspberry Pi and NVIDIA Jetson.

### Build

Use the full .NET platform and tooling such as Visual Studio and plug-and-play hardware drivers to painlessly build IoT solutions.

### Connect

Utilize native support for WiFi, Ethernet, and Cellular connectivity to send sensor data to the Cloud and remotely control your peripherals.

### Deploy

Instantly deploy and manage your fleet in the cloud for OtA, health-monitoring, logs, command + control, and enterprise backend integrations.


Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Meadow;
//#define DEVICE_FEATHER
#define DEVICE_PROJECT_LAB
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Sensors.Distance;
using Meadow.Units;
Expand All @@ -8,7 +10,12 @@
namespace A02yyuw_Sample
{
// Change F7FeatherV2 to F7FeatherV1 for V1.x boards
#if DEVICE_FEATHER // Feather: Change F7FeatherV2 to F7FeatherV1 for V1.x boards
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting idea, we should think about something like this and apply it to all samples in the repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a cleaner pattern for this that doesn't require compiler directives. See this as an example:

public class MeadowApp : App<F7FeatherV2>
#endif
#if DEVICE_PROJECT_LAB //ProjectLab: uses an F7CoreComputeV2 board
public class MeadowApp : App<F7CoreComputeV2>
#endif
{
//<!=SNIP=>

Expand All @@ -18,7 +25,7 @@ public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

a02yyuw = new A02yyuw(Device, Device.PlatformOS.GetSerialPortName("COM4"));
a02yyuw = new A02yyuw(Device, Device.PlatformOS.GetSerialPortName("COM4"), A02yyuw.MODE_UART_CONTROL);

var consumer = A02yyuw.CreateObserver(
handler: result =>
Expand Down