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

[SHT4x] Read serial number of sensor module #2091

Merged
merged 2 commits into from
Jun 29, 2023
Merged

Conversation

gjnijenhuis
Copy link
Contributor

@gjnijenhuis gjnijenhuis commented Jun 26, 2023

The current module has no implementation for reading the serial number of the SHT4x device.
This PR implements the reading of the serial number of the SHT4x device.

Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Jun 26, 2023
@gjnijenhuis
Copy link
Contributor Author

@dotnet-policy-service agree

@pgrawehr
Copy link
Contributor

/azp run dotnet.iot

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

ushort? msb = Sensirion.ReadUInt16BigEndianAndCRC8(buffer);
ushort? lsb = Sensirion.ReadUInt16BigEndianAndCRC8(buffer.Slice(3, 3));

return lsb + (msb << 16);
Copy link
Member

Choose a reason for hiding this comment

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

why not using version instead of an int?
You definitely get 2 elements:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In to the example C code provided by Sensirion the serial number is also output as a 32 bit integer. When the manufacturer of the chip interprets the serial number in this way I think it would be best to be consistent and also use a 32 bit integer here.

https://github.com/Sensirion/embedded-sht/blob/master/sht4x/sht4x.c#L103

Copy link
Member

Choose a reason for hiding this comment

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

ok but on this example code, nothing is done with this int. So the question is: how to properly use this version? Are there some specific int versions which can be tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, in this code the serial is just stored in a 32 bit integer, at the pointer which was passed through at function call. There is no example code that uses it.

The Adafruit library has it also implemented in a similar way and has an example on how the serial is used:

Code:
https://github.com/adafruit/Adafruit_SHT4X/blob/master/Adafruit_SHT4x.cpp#L83

Example:
https://github.com/adafruit/Adafruit_SHT4X/blob/master/examples/SHT4test/SHT4test.ino#L26

Serial.println("Found SHT4x sensor");
Serial.print("Serial number 0x");
Serial.println(sht4.readSerial(), HEX);

Copy link
Member

Choose a reason for hiding this comment

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

ok, still, there is no check. So I4m fine with this int.

@Ellerbach Ellerbach merged commit 30f0875 into dotnet:main Jun 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants