Read two thousand three hundred and two | return seven

A grain of gold sand (advanced)

Building owner
 

SparkFun Pro nRF52840 Mini Bluetooth Development Board ADC [Copy Link]

This post was finally edited by Yuban 10032 at 15:54 on June 1, 2024

Digression

 

Arduino is very simple to implement ADC functions, so in recent articles, the functions of peripherals like IIC, USART, SPI, etc. We all achieve it quickly. And use the sensor corresponding to the protocol to realize the Demo function.

What we want to achieve today is to use the ADC function on this development board to read the voltage output of the gas quality sensor and send it to the upper computer through the serial port.

 

text

 

According to the schematic diagram, there are 8 pins on this development board that can be used for ADC input, as shown in the figure below

  

The data manual also clearly describes the current ADC, to the effect that 12 bit ADC has 8 channels

 

 

Now let's start the coding part. Sparkfun actually provides us with Demo examples. We can open the official demo through the following figure

 

 

The codes are as follows:

 #include <Arduino.h> #include <Adafruit_TinyUSB.h> // for Serial int adcin    = A5; int adcvalue = 0; float mv_per_lsb = 3600.0F/1024.0F; // 10-bit ADC with 3.6V input range void setup() { Serial.begin(115200); while ( ! Serial ) delay(10);   //  for nrf52840 with native usb } void loop() { // Get a fresh ADC value adcvalue = analogRead(adcin); // Display the results Serial.print(adcvalue); Serial.print(" ["); Serial.print((float)adcvalue * mv_per_lsb); Serial.println(" mV]"); delay(100); }

 

But actually you notice that the current ADC conversion is performed at 10 bit resolution. The official data manual provides 12 digit ADC.

 

So at this time, we need to adjust the ADC resolution so that it can run at 12 bit resolution.

At this time, we need to query the Arduino API analog Part of the description of the resolution (I will take a detailed look at the API description in this part, which is definitely not for water articles!)

 

 

 

For the Analog part, Arduino provides five APIs, namely:

  1. Read the converted value of a Pin( analogRead() )
  2. Set the read resolution( analogReadResolution() )
  3. Set reference voltage( analogReference() )
  4. Write the specified voltage of a PIN bit in PWM mode( analogWrite() )
  5. Set Write Resolution( analogWriteResolution() )

The above roughly means that the default is ten bit ADC. You can set the ADC bit supported by your board through this API. If you set the resolution of 12 to 16 bit ADC, the result of analylogread() will be affected by the approximation

 

So let's modify the original program function to support a 12 bit resolution. We just need to set the resolution to 12 bits before reading the ADC value, and then according to 2 ^ 12=4096 Set the calculated value

 

 #include <Arduino.h> #include <Adafruit_TinyUSB.h> // for Serial int adcin    = A5; int adcvalue = 0; float mv_per_lsb = 3600.0F/4096.0F; // 12-bit ADC with 3.6V input range void setup() { Serial.begin(115200); while ( ! Serial ) delay(10);   //  for nrf52840 with native usb analogReadResolution(12); } void loop() { // Get a fresh ADC value adcvalue = analogRead(adcin); // Display the results Serial.print(adcvalue); Serial.print(" ["); Serial.print((float)adcvalue * mv_per_lsb); Serial.println(" mV]"); delay(100); }

After modification, short the ADC to 3.3. If the mv you read is basically equal to the value of 10 bit resolution ADC, the test result is correct

 

Effect demonstration:

 

June 1 (1)

 

In the next section, we will study how to send the converted data through Bluetooth

This post is from RF/Wireless Forum

Latest reply

The main board has a Bluetooth protocol stack, which is really troublesome.   details reply Published on June 4, 2024-10:01
give the thumbs-up follow
 

reply
report

Pure silicon (advanced)

sofa
 

Thank you for sharing the technical knowledge, which is very helpful to me as a beginner. Thank you very much

This post is from RF/Wireless Forum

comment

Learn together details reply Published at 23:34, June 1, 2024
 
 

reply

A grain of gold sand (advanced)

Bench
 
Chejm published on 2024-6-1 20:52 Thank you for sharing the technical knowledge, which is very helpful to me as a beginner. Thank you very much

Learning together

This post is from RF/Wireless Forum
 
 
 

reply

Moderator

four floor
 

Written with arduino? This feels very efficient.

This post is from RF/Wireless Forum

comment

This board supports Arduino, and many official demos are provided It's very convenient to use   details reply Published at 23:30, June 3, 2024
 
 
 

reply

A grain of gold sand (advanced)

five floor
 
Wangerxian published at 2024-6-3 10:37 Written with arduino? This feels very efficient.

This board supports Arduino, and many official demos are provided It's very convenient to use

This post is from RF/Wireless Forum

comment

The main board has a Bluetooth protocol stack, which is really troublesome.   details reply Published on June 4, 2024-10:01
It may be a bit troublesome when setting up the environment. The rest is to understand the code provided by the official and implement the function with your own Idea details reply Published at 23:31, June 3, 2024
 
 
 

reply

A grain of gold sand (advanced)

six floor
 
Yuban 10032, published at 23:30, June 3, 2024 This board supports Arduino, and many official demos are provided It's very convenient to use

It may be a bit troublesome when setting up the environment. The rest is to understand the code provided by the official and implement the function with your own Idea

This post is from RF/Wireless Forum
 
 
 

reply

Moderator

seven floor
 
Yuban 10032, published at 23:30, June 3, 2024 This board supports Arduino, and many official demos are provided It's very convenient to use

The main board has a Bluetooth protocol stack, which is really troublesome.

This post is from RF/Wireless Forum

comment

Yes, I read the official Demo about Bluetooth, without considering the details It's very simple to just talk about the use of API details reply Published at 12:13 on June 4, 2024
 
 
 

reply

A grain of gold sand (advanced)

eight floor
 
Wangerxian published at 10:01 on June 4, 2024 The main board has a Bluetooth protocol stack, which is really troublesome.

Yes, I read the official Demo about Bluetooth, without considering the details It's very simple to just talk about the use of API

This post is from RF/Wireless Forum
 
 
 

reply
You need to log in before you can reply Sign in | register

Guess you like it
look around
Find Data Book?

EEWorld Datasheet Technical Support

Related articles More>>
Quick reply Back to top Back to list