Comments (9)
Hi @Alex507507507 I edited your comment such that the code has syntax highlighting, I hope you don't mind.
The Serial Monitor shows this message:
~ ⸮+~ probe failed ~ ⸮+~ probe failed ~ ⸮+~ probe failed
It looks like you are using the same serial port for the connection to the sps30 as is used for the USB serial monitor. This won't work since there will be conflicts.
Is there another Serial port available on your Arduino board? See also https://www.arduino.cc/reference/en/language/functions/communication/serial/ for Serial ports available for common Arduino boards.
s16 sensirion_uart_open() {
You should have a Serial1.begin(BAUDRATE)
there, where Serial1
may need to change depending on your Arduino board.
If there is no additional Serial port available you may try to use the https://www.arduino.cc/en/Reference/SoftwareSerial library.
from embedded-uart-sps.
Serial11.begin(9600);
This looks like the wrong baudrate. Try to use the defined BAUDRATE
value which is 115200.
from embedded-uart-sps.
I tried adding the start function to the arduino_sps30_example, but I could not find a way to turn on the ventilator and to start communicating. I also tried to add replace some "serial" to "Serial11" in the sps30 library.
Could you verify the following things:
- You did call
sensirion_uart_open();
in thesetup
function sps30_probe
did work (so no error message on the Serial Monitor in Arduino.- The same for
sps30_start_measurement
from embedded-uart-sps.
I changed the bautrate to 115000.
I guess this is a typo? If not, change it to 115200
Therefore the sps_probe has an error.
Yes, so communication doesn't seem to work. Could you verify that the TX (transmit) of the Node MCU is connect to RX (receive) of the SPS30 and RX of the Node MCU to TX of the SPS accordingly?
What about the fourth pin for interface select: it says it should be "left floating" for uart.
From googling I thought it should be just hanging without connecting it. Is it right?
Yes, "left floating" means to not connect it.
The ventilator is not turning.
The ventilator will only start when the device is measuring, to save power if not measuring. So as long as sps30_start_measurement
fails it won't.
from embedded-uart-sps.
Hello
@rnestler , thank you for your answer and your advise to use the software serial and to highlight the code.
I added the software serial 2 to the sensirion_uart_implementation to read the values. D1 and D2 are the Pins of the NodeMCU. The implementations are the implementations from the sample.
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
/*
* Copyright (c) 2018, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
*/
#include "sensirion_arch_config.h"
#include "sensirion_uart.h"
#include <SoftwareSerial.h>
#include <Arduino.h>
SoftwareSerial Serial11(D1, D2);
/*
* INSTRUCTIONS
* ============
*
* Implement all functions where they are marked with TODO: implement
* Follow the function specification in the comments.
*/
/**
* sensirion_uart_open() - initialize UART
*
* Return: 0 on success, an error code otherwise
*/
s16 sensirion_uart_open() {
Serial11.begin(9600);
while (!Serial11) {
delay(100);
}
return 0;
}
/**
* sensirion_uart_close() - release UART resources
*
* Return: 0 on success, an error code otherwise
*/
s16 sensirion_uart_close() {
Serial11.end();
return 0;
}
/**
* sensirion_uart_tx() - transmit data over UART
*
* @data_len: number of bytes to send
* @data: data to send
* Return: Number of bytes sent or a negative error code
*/
s16 sensirion_uart_tx(u16 data_len, const u8 *data) {
return Serial11.write(data, data_len);
}
/**
* sensirion_uart_rx() - receive data over UART
*
* @data_len: max number of bytes to receive
* @data: Memory where received data is stored
* Return: Number of bytes received or a negative error code
*/
s16 sensirion_uart_rx(u16 max_data_len, u8 *data) {
s16 i = 0;
while (Serial11.available() > 0 && i < max_data_len) {
data[i] = (u8)Serial11.read();
i++;
}
return i;
}
/**
* Sleep for a given number of microseconds. The function should delay the
* execution for at least the given time, but may also sleep longer.
*
* Despite the unit, a <10 millisecond precision is sufficient.
*
* @param useconds the sleep time in microseconds
*/
void sensirion_sleep_usec(u32 useconds) {
delay((useconds / 1000) + 1);
}
I tried adding the start function to the arduino_sps30_example, but I could not find a way to turn on the ventilator and to start communicating. I also tried to add replace some "serial" to "Serial11" in the sps30 library.
How to indicate the sensor to start measuring properly?
Thank you in advance and best regards
Alex
from embedded-uart-sps.
Hello,
@rnestler Thank you for your answer and your recommendations.
I changed the bautrate to 115000.
- The
sensirion_uart_open();
function is inside thesetup
function - The
serial monitor
shows the error message
probe failed, probe failed ...
Therefore the sps_probe has an error.
if I remove that while loop the sps30_start_measurement
also returns the error message.
read measurement failed, read measurement failed ...
when I print out the value before
sps30_read_measurement(&measurement);
then ret=0
when printing it out after
sps30_read_measurement(&measurement);
then ret=-2.
What about the fourth pin for interface select: it says it should be "left floating" for uart.
From googling I thought it should be just hanging without connecting it. Is it right?
The ventilator is not turning.
(Somehow I could make the ventilator turn somehow before, however, I didn't realize it so I don't know how I made it run before... couldn't repeat that.. At least it's not broken.)
Any other ideas?
Thank you a lot in advance and best regards
Alex
from embedded-uart-sps.
@Alex507507507 Did you get it working, and if so, would you provide us with a working sample? Either here or as pull-request. Thanks.
from embedded-uart-sps.
Hello
please find the working example. Thank you for your help, sorry for answering that late. There is still a problem with sensirion_uart_close() when transfering the data to a server, however without it it works.
#include <sensirion_arch_config.h>
#include <sensirion_shdlc.h>
#include <sensirion_uart.h>
/*
Copyright (c) 2018, Sensirion AG
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Sensirion AG 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
*/
#include <Arduino.h>
#include "sensirion_uart.h"
#include "sps30.h"
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(100);
}
// use built-in LED to show errors
sensirion_uart_open();
s16 sps30_start_measurement();
}
void loop() {
struct sps30_measurement measurement;
s16 ret;
Serial.println(ret);
while (sps30_probe() != 0) {
Serial.write("probe failed\n");
delay(1000);
}
/* start measurement and wait for 10s to ensure the sensor has a
* stable flow and possible remaining particles are cleaned out */
if (sps30_start_measurement() != 0) {
Serial.write("error starting measurement\n");
}
delay(10000);
while (1) {
delay(1000);
ret = sps30_read_measurement(&measurement);
if (ret < 0) {
Serial.write("read measurement failed\n");
} else {
if (SPS_IS_ERR_STATE(ret)) {
Serial.write("Measurements may not be accurate\n");
}
Serial.println("Measurements:");
Serial.write("PM 1.0: ");
Serial.println(measurement.mc_1p0, DEC);
Serial.write("PM 2.5: ");
Serial.println(measurement.mc_2p5, DEC);
Serial.write("PM 4.0: ");
Serial.println(measurement.mc_4p0, DEC);
Serial.write("PM 10: ");
Serial.println(measurement.mc_10p0, DEC);
Serial.write("Number Concentration PM 1: ");
Serial.println(measurement.nc_1p0, DEC);
Serial.write("Number Concentration PM 2: ");
Serial.println(measurement.nc_2p5, DEC);
Serial.write("Number Concentration PM 4: ");
Serial.println(measurement.nc_4p0, DEC);
Serial.write("Number Concentration PM 10: ");
Serial.println(measurement.nc_10p0, DEC);
Serial.println(" ");
}
}
sps30_stop_measurement();
sensirion_uart_close();
}
Here is the library sensirion_uart
/*
* Copyright (c) 2018, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
*/
#include "sensirion_arch_config.h"
#include "sensirion_uart.h"
#include <SoftwareSerial.h>
#include <Arduino.h>
SoftwareSerial Serial11(D1, D2);
/*
* INSTRUCTIONS
* ============
*
* Implement all functions where they are marked with TODO: implement
* Follow the function specification in the comments.
*/
/**
* sensirion_uart_open() - initialize UART
*
* Return: 0 on success, an error code otherwise
*/
s16 sensirion_uart_open() {
Serial11.begin(115200);
while (!Serial11) {
delay(100);
}
return 0;
}
/**
* sensirion_uart_close() - release UART resources
*
* Return: 0 on success, an error code otherwise
*/
s16 sensirion_uart_close() {
Serial11.end();
return 0;
}
/**
* sensirion_uart_tx() - transmit data over UART
*
* @data_len: number of bytes to send
* @data: data to send
* Return: Number of bytes sent or a negative error code
*/
s16 sensirion_uart_tx(u16 data_len, const u8 *data) {
return Serial11.write(data, data_len);
}
/**
* sensirion_uart_rx() - receive data over UART
*
* @data_len: max number of bytes to receive
* @data: Memory where received data is stored
* Return: Number of bytes received or a negative error code
*/
s16 sensirion_uart_rx(u16 max_data_len, u8 *data) {
s16 i = 0;
while (Serial11.available() > 0 && i < max_data_len) {
data[i] = (u8)Serial11.read();
i++;
}
return i;
}
/**
* Sleep for a given number of microseconds. The function should delay the
* execution for at least the given time, but may also sleep longer.
*
* Despite the unit, a <10 millisecond precision is sufficient.
*
* @param useconds the sleep time in microseconds
*/
void sensirion_sleep_usec(u32 useconds) {
delay((useconds / 1000) + 1);
}
Best regards
Alexander
from embedded-uart-sps.
I'll close this, since there wasn't any activity and the solution from @Sebastiang507 seems to work.
from embedded-uart-sps.
Related Issues (20)
- sps30_stop_measurement issuing the wrong command HOT 3
- Adafruit Feather 32u4 Bluefruit LE: Unable to receive data HOT 6
- Distinguish between different SENSIRION_SHDLC_ERR_MISSING_STOP errors HOT 4
- Voltage via UART? HOT 3
- Only getting NaN readings via UART on Raspberry Pi 3 HOT 4
- SPS30 communication on uart HOT 1
- help wanted for SPS30 with UART communication HOT 2
- Atmel SAM4S implementation HOT 2
- Handle SHDLC Execution Error Codes and Device Error Flag properly
- uart-sps HOT 8
- Arduino example wrong #define HOT 2
- Support for Nano 33 BLE Sense HOT 4
- 40: internal function argument out of range HOT 2
- Output format is float values only — integer format not supported HOT 2
- First measurement read in sps30_example_usage.c always fails HOT 1
- Sps30 HOT 1
- UART HAL Recieve HOT 2
- STM32 UART EXAMPLE SPS30 HOT 3
- sensor probing failed HOT 4
- SPS30 with STM32F401 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embedded-uart-sps.