My CLUE sensor data rate is 208HZ, which means that it generates 208 data per second.
Even though the accelerator sensor can generate 208 data per second, the while loop in python code only works about 50 times per second, which means that it only shows about 50 data.
I wonder whether there are any alternative solutions to collect 208 data per second.
Currently, it can only collect about 50 data per second.
Syncronixation of CLUE and While loop
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- dastels
- Posts: 15819
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Syncronixation of CLUE and While loop
The obvious solution is to switch to C++/Arduino. That should let you get a full 208 readings second.
Are you printing in your loop? That's a very slow operation. If you remove that you can get more readings. Maybe only read for a second (or more depending on memory) then output it all at once. You'll miss readings while printing but you should be able to get a higher frequency of them while you are reading.
take out everything in the loop you don't need there.
But in the end, CircuitPython is slow (well, slower than C++) and isn't meant for writing highspeed code.
Dave
Are you printing in your loop? That's a very slow operation. If you remove that you can get more readings. Maybe only read for a second (or more depending on memory) then output it all at once. You'll miss readings while printing but you should be able to get a higher frequency of them while you are reading.
take out everything in the loop you don't need there.
But in the end, CircuitPython is slow (well, slower than C++) and isn't meant for writing highspeed code.
Dave
- HyunjunCHoi
- Posts: 5
- Joined: Wed Apr 13, 2022 1:37 am
Re: Syncronixation of CLUE and While loop
Thank you for your reply.
Based on your answer, I will switch python to C++/Arduino.
I have several questions.
Currently, the Adafruit CLUE sensor sends data to raspberry pi using UART.
Of course, all codes were written in python.
Can I write the codes in C++?
Because I never used C++, I have no idea what I should start first.
If you do not mind, could you share any examples of code or materials to help me to write the code in C++?
Thank you.
Based on your answer, I will switch python to C++/Arduino.
I have several questions.
Currently, the Adafruit CLUE sensor sends data to raspberry pi using UART.
Of course, all codes were written in python.
Can I write the codes in C++?
Because I never used C++, I have no idea what I should start first.
If you do not mind, could you share any examples of code or materials to help me to write the code in C++?
Thank you.
- dastels
- Posts: 15819
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Syncronixation of CLUE and While loop
Yes, anything you can do in Python, you can do in C++. Note that you'll only need to rewrite the CLUE code in C++. There is loads of material online and in books for learning C++; it's been around since the late 80s. A good book to start with in the context of Arduino is https://www.amazon.com/Programming-Ardu ... 1259641635, followed by https://www.amazon.com/Programming-Ardu ... B07J1DNF5V.
All the sensor libraries will include examples. The best place to start is probably https://learn.adafruit.com/adafruit-clu ... port-setup. The page https://learn.adafruit.com/adafruit-clue/arduino-test talks about the test code that uses all the sensors.
Dave
All the sensor libraries will include examples. The best place to start is probably https://learn.adafruit.com/adafruit-clu ... port-setup. The page https://learn.adafruit.com/adafruit-clue/arduino-test talks about the test code that uses all the sensors.
Dave
- HyunjunCHoi
- Posts: 5
- Joined: Wed Apr 13, 2022 1:37 am
Re: Syncronixation of CLUE and While loop
Thank you so much for your help.
- HyunjunCHoi
- Posts: 5
- Joined: Wed Apr 13, 2022 1:37 am
Re: Syncronixation of CLUE and While loop
I have one more question.
Currently, I am using wireless communication between the Adafruit CLUE sensor and raspberry pi.
I am studying the materials that you shared to switch to C++/Arduino.
I just wonder whether wireless communication will still cause a slow data collection rate like what I experienced in python, even though I switch to C++/Arduino.
Currently, I am using wireless communication between the Adafruit CLUE sensor and raspberry pi.
I am studying the materials that you shared to switch to C++/Arduino.
I just wonder whether wireless communication will still cause a slow data collection rate like what I experienced in python, even though I switch to C++/Arduino.
- dastels
- Posts: 15819
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Syncronixation of CLUE and While loop
It depends on how much data is transferred each time and how long that takes. Let's say your goal is 200 data reading per second, That's a reading every 5 mS. If you can send a reading in less than 5mS then you should be ok.
Another question is do you need readings that frequently?
You can get into more advanced techniques like using a time interrupt to do a reading and put it in a buffer. The main loop repeatedly sends out a reading (or a clump of readings.. it's all about what works with the timings) from the buffer (and removes it).
Dave
Another question is do you need readings that frequently?
You can get into more advanced techniques like using a time interrupt to do a reading and put it in a buffer. The main loop repeatedly sends out a reading (or a clump of readings.. it's all about what works with the timings) from the buffer (and removes it).
Dave
Last edited by dastels on Thu May 19, 2022 1:51 pm, edited 1 time in total.
Reason: typo
Reason: typo
- HyunjunCHoi
- Posts: 5
- Joined: Wed Apr 13, 2022 1:37 am
Re: Syncronixation of CLUE and While loop
Hello Dave
Let me explain what I am doing.
I have Data Sender(Adafruit CLUE sensor) and Data receiver - Bluefruit Connect app (made by adafruit).
The data is sent from the CLUE sensor to the Bluefruit Connect app over Bluetooth.
I can check that data is updated in the Bluefruit Connect app.
However, I am trying to implement Data receiver code for the Adafruit CLUE sensor in C++, which means I want to make my own client in C++.
I have struggled to implement the client code in C++.
If you do not mind, please could you share any ideas or materials to help me to implement the client in C++?
Best,
Jun
Let me explain what I am doing.
I have Data Sender(Adafruit CLUE sensor) and Data receiver - Bluefruit Connect app (made by adafruit).
The data is sent from the CLUE sensor to the Bluefruit Connect app over Bluetooth.
I can check that data is updated in the Bluefruit Connect app.
However, I am trying to implement Data receiver code for the Adafruit CLUE sensor in C++, which means I want to make my own client in C++.
I have struggled to implement the client code in C++.
If you do not mind, please could you share any ideas or materials to help me to implement the client in C++?
Best,
Jun
- dastels
- Posts: 15819
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Syncronixation of CLUE and While loop
I thought you were sending to a Raspberry Pi.
Anyway, you're getting out of my depth with bluetooth. I'd start by looking at the bluetooth related guide: https://learn.adafruit.com/search?q=bluetooth and the "help-with-radio" channel in the Adafruit Discord https://learn.adafruit.com/welcome-to-c ... -2976147-3.
Dave
Anyway, you're getting out of my depth with bluetooth. I'd start by looking at the bluetooth related guide: https://learn.adafruit.com/search?q=bluetooth and the "help-with-radio" channel in the Adafruit Discord https://learn.adafruit.com/welcome-to-c ... -2976147-3.
Dave
Please be positive and constructive with your questions and comments.