ESP32 DevKitC v4 not scanning **some** BLE Signals (but ESP32 DevKitC V2 does) - bluetooth-lowenergy

For a work-related project, I developed a program using the ESP32 DevKitC V2 to scan for smart-beacons with specific MAC-Addresses. Everything was working fine until I decided to buy some DevKit V4. On the DevKit V4, it still scans some BLE Advertising signals but somehow not anymore the ones from the smart-beacons I need to track. The smart-beacons are the Smart Beacon Go Mini from blukii. The smart-beacons only act as BLE advertisers and advertise every second. I'm not trying to connect to them.
My questions are:
Do the DevKit V4 have different BLE capabilities than the V2? (couldn't find anything googling)
Any idea to solve this problem?
I develop using Platformio on VSCode.
platform.ini:
[env:esp32dev]
framework = arduino
platform = espressif32
board = az-delivery-devkit-v4
board_build.partitions = huge_app.csv
monitor_speed = 115200
lib_deps =
h2zero/NimBLE-Arduino#^1.4.0
main.cpp:
#include <Arduino.h>
#include "NimBLEDevice.h"
const int NUMBER_SCAN = 40; // number of scans to perform
const int SCAN_DURATION = 1.1; // duration of a scan in seconds
NimBLEScan *pBLEScan;
void collectAdvertisingPackets()
{
// scan NUMBER_SCAN times
for (int i = 0; i < NUMBER_SCAN; i++)
{
NimBLEScanResults result = pBLEScan->start(SCAN_DURATION);
// number of advertising devices found
int count = result.getCount();
Serial.printf("Total devices found: %d\n", count);
// for each device found
for (int j = 0; j < count; j++)
{
NimBLEAdvertisedDevice device = result.getDevice(j);
std::string macAddress = device.getAddress().toString();
Serial.println(macAddress.c_str());
}
pBLEScan->clearResults(); // delete results from BLEScan buffer to release memory
}
}
void setup()
{
// baudrate for serial communication
Serial.begin(115200);
// BLE scan
NimBLEDevice::init(""); // initialize the ESP32 microcontroller as a BLE device
pBLEScan = NimBLEDevice::getScan();
}
void loop()
{
collectAdvertisingPackets();
}
Any advice is greatly appreciated :)
What did I try: Wrote the code with another library (Neil Kolban BLE library), googling to find if this problem exists. BLE Advertising Signals from the blukii smart beacons are scanned by the ESP32 DevKitC V2 but not by the V4.
What I expected: BLE Advertising Signals from the Blukii Smart Beacons Go Mini to be scanned by the ESP32 DevKitC V4 (which works with the ESP32 DevKitC V2).

Related

my serial port did not show my sensor data properly

Hey i got a bit problem with my Arduino and sensor
Here is what i tried ;
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
#include <SoftwareSerial.h>
SoftwareSerial blue(0,1);
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550;
PulseSensorPlayground pulseSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
blue.begin(9600);
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat.
pulseSensor.setThreshold(Threshold);
pulseSensor.begin();
}
void loop() {
// put your main code here, to run repeatedly:
int myBPM = pulseSensor.getBeatsPerMinute();
if(myBPM>200){
myBPM-100;
}
if (pulseSensor.sawStartOfBeat()) {
Serial.println(myBPM);
blue.println(myBPM);
}
delay(10);
}
this code I got from the example library and modified it.
so i want to send data to my android using Bluetooth but this sensor kinda ticked me off because whenever i use it with my HC-06 Bluetooth module it suddenly got a hearth beat without i even touching it and it just sends so much data ignoring the delay I set.
I just need to slowly sending data just like a second but the data didn't show up
so anyone can help?
I read your code and I noticed this piece of code
if(myBPM > 200){ myBPM - 100; }
that is poorly written if (I understand correctly) you want to check the size of myBPM and if it is larger than 200 then it should be subtracted 100.
it should be:
myBPM = myBPM - 100; not myBPM - 100;
I hope my answer will help you. Have a nice day!

How to read XBee RSSI in API mode?

I am trying to test a XBee RSSI in API mode at receiving end, how can I retrieve the RSSI value of the receiving radio in arduino.
I configured both XBee in API-2 mode and are connected to arduino by pin 4-5(rxtx & txrx) to Xbee radios.
Sending frame code is like below and there is no problem in transmission at both ends,
uint8_t data[] = {'H','i'};
XBeeAddress64 addr64 = XBeeAddress64();
addr64.setMsb(0x00000000); // Msb address of receiver
addr64.setLsb(0x00000000); // Lsb address of receiver
ZBTxRequest zbTx = ZBTxRequest(addr64, data, sizeof(data));
xbee.send(zbTx);
delay(1000);
At the receiving end I tried pulseIn of arduino and .getRssi() of , The former function gives "0" in result while the later gives "102" but remains the same as I move the Xbee radios away from each other.
What should I need to do for getting correct RSSI at the receiving end..?
Hopefully this answer helps you and others.
Assuming you are using the following lib:
https://github.com/andrewrapp/xbee-arduino
and you have a series 1 module you can use the following test code for quick diagnostics. the commented parts can of course also be used if needed
#include <XBee.h>
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 8 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 9 (Arduino's Software TX)
SoftwareSerial serial1(8, 9); // RX, TX
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();
// uint8_t xbeeOption = 0;
// uint8_t xbeeData = 0;
uint8_t xbeeRssi = 0;
void setup() {
Serial.begin(9600);
serial1.begin(9600);
xbee.setSerial(serial1);
}
void loop() {
xbee.readPacket(100);
if (xbee.getResponse().isAvailable()) {
Serial.println("Xbee available");
if (xbee.getResponse().getApiId() == RX_64_RESPONSE || xbee.getResponse().getApiId() == RX_16_RESPONSE) {
Serial.println("64 or 16");
if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
Serial.println("16");
xbee.getResponse().getRx16Response(rx16);
// xbeeOption = rx16.getOption();
//Serial.print("xbeeOption: "); Serial.println(xbeeOption);
//xbeeData = rx16.getData(0);
//Serial.print("xbeeData: "); Serial.println(xbeeData);
xbeeRssi = rx16.getRssi();
Serial.print("xbeeRssi: "); Serial.println(xbeeRssi);
}
else {
Serial.println("64");
xbee.getResponse().getRx64Response(rx64);
//xbeeOption = rx64.getOption();
//Serial.print("xbeeOption: "); Serial.println(xbeeOption);
//xbeeData = rx64.getData(0);
//Serial.print("xbeeData: "); Serial.println(xbeeData);
xbeeRssi = rx64.getRssi();
Serial.print("xbeeRssi: "); Serial.println(xbeeRssi);
}
}
}
If you use a series2 module there is only the way using the hardware pwm signal: In order for the RSSI pwm signal to be updated it needs to have received an API packet. Also, for the series 2 Xbee this applies only for the last hop of the packet, so from last router to destination. You need to use the XBee rssi pin and some coding depending on your appliance.
The rssi for distance is not very reliable and you will see a change perhaps every 10 to 15 meters while sending packets. So just moving a Xbee around on your workplace will not change the values.
EDIT:
When using a series 2 module there is the following possibility: connect the rssi pin of the xbee (6) to an Arduino pwm pin (eg 10) and measure the incoming signal, which could then be mapped to a quality or/and distance range. So writing your own rssi function. The usual xbee libs only support series1 modules.

Incorrect measurements with Arduino HX711 and cc2541 Bluetooth module

I am using Arduino Nano with HX711 scales module and cc2541 Bluetooth module(Bluetooth 4.0) to send data to Android device.
#define RX 11
#define TX 10
#include "HX711.h"
HX711 scale(A1, A0);
float scale_calibration = -13.5;
float mass,massround;
float units;
int out;
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(TX, RX);
void setup()
{
bluetooth.begin(9600);
scale.set_scale();
scale.tare();
scale.set_scale(scale_calibration);
}
void loop()
{
for(int i = 0;i < 10; i ++) units =+ scale.get_units(), 1;
units / 10;
mass = units * 0.035274;
massround=mass;
out = round(massround);
out = abs(out);
if(out<0)
{
out=0;
scale.tare();
}
bluetooth.println(out);
}
If I run Arduino using USB coonected to my PC, the scales work perfect and give right results via Bluetooth. However, when I run Arduino using battery (not connected to PC), I get 0-3 grams value, while there is nothing on the scales. So because of that all measurements are incorrect. How can I fix this problem?
When your Arduino is powered from USB, it and the HX711 probably have both VCC and VDD at +5 volts, making the 'reference' voltage (VDD) 5 volts.
When running off battery, the hardware is receiving ~3 volts, and if VCC and VDD are shorted together on the HX711, it might 'kinda work' but would give spurious results.
There's probably jumpers or bridges to set VCC and VDD on both the arduino and the load cell. CAUTION! I'm just guessing here, and be sure to read the tech docs before changing the voltage settings, it's easy to cook these little circuits with a minor change in voltages.
This might be better asked in a hardware or electrical engineering channel.

receiving data from pc to PIC 16F877A with compiler hi-tech

I try to send the data from pc to the pic microcontroller. I am a beginner in PIC.
I send the data from hyperterminal and the data will display in the led in port B of PIC.
I used 10Mhz clock and the connection in 9600 baudrate.
here my uart.h program:
char UART_Init(const long int baudrate)
{
unsigned int x;
x = (_XTAL_FREQ - baudrate*64)/(baudrate*64);
if(x>255)
{
x = (_XTAL_FREQ - baudrate*16)/(baudrate*16);
BRGH = 1;
}
if(x<256)
{
SPBRG = x;
SYNC = 0;
SPEN = 1;
TRISC7 = 1;
TRISC6 = 1;
CREN = 1;
TXEN = 1;
return 1;
}
return 0;
}
char UART_TX_Empty()
{
return TRMT;
}
char UART_Data_Ready()
{
return RCIF;
}
char UART_Read()
{
while(!RCIF);
return RCREG;
}
void UART_Read_Text(char *Output, unsigned int length)
{
int i;
for(int i=0;i<length;i++)
Output[i] = UART_Read();
}
void UART_Write(char data)
{
while(!TRMT);
TXREG = data;
}
void UART_Write_Text(char *text)
{
int i;
for(i=0;text[i]!='\0';i++)
UART_Write(text[i]);
}
and this is my main program:
#include<htc.h>
#include<pic.h>
#define _XTAL_FREQ 10000000 //Clock Frequency
#include "uart.h"
void main()
{
TRISB = 0x00; //PORTB as Output
UART_Init(9600);
do
{
if(UART_Data_Ready())
PORTB = UART_Read();
__delay_ms(1000);
}while(1);
}
in hyperteminal I send data say 10010010 but the led in port B do not respond, are there any error in my program?
You have several steps: initialize UART, initialize LEDs, communicate over UART and setup your PC's UART. Which components have you successfully written and tested? You say you're a beginner, so what is the smallest functional program you have successfully executed on a PIC? I've been working with microcontrollers for years, but I still schedule about a whole day to get a single LED to turn on because it could be a software problem, a hardware problem, a voltage problem, an oscillator problem, a PCB problem or a compiler problem.
Here are the steps I take for microchip bring up:
Go over the oscillator section, the configuration bits section, the watchdog section and the pinout section (looking for VDD and VSS) in the datasheet. These are some of the hardest parts to get right. (A gotcha about the oscillator: just because you can program a chip, doesn't mean the oscillator is working because the programmer provides it's own clock.)
Write the bare-minimum code to turn on a single LED.
Write the bare-minimum code to make the LED blink (just use a for-loop delay for now, timers come later)
Write UART initialization code and transmit a single character, I use captial U because it's pretty in binary. TXREG = 'U';
Connect the UART to a PC and see if the hyperterminal sees the U. If it doesn't, I connect an oscilscope to the lines to make sure that the PIC is transmitting, that the PC transmits when I type characters and that the timing of the edges matches.
Within the PIC code, have the UART echo characters from the terminal. (TXREG = RXREG;), and then type on the hyperterminal and make sure the characters are echoed back.
One more note:
Do not have the PIC perform the SPBRG calculation. PIC16 are 8-bit processors and 10000000 requires 32-bits to store. There might be hiccups with the integer divison. It might not have a bug in it, but there's no need to have the PIC calculate it each time. Calculate it before-hand and hard-code the value.

Freescale Pressure Sensor MPL3115A2 I2C communication with Arduino

Does anyone have experience with the MPL3115A2 Freescale I2C pressure sensor?
I need to use it in a project concerning Arduino UNO r3, but I can't get communication between them correctly. Here is my code:
#include <Wire.h>
void setup(){
Serial.begin(9600);
/*Start communication */
Wire.begin();
// Put sensor as in Standby mode
Wire.beginTransmission((byte)0x60); //0x60 is sensor address
Wire.write((byte)0x26); //ctrl_reg
Wire.write((byte)0x00); //reset_reg
Wire.endTransmission();
delay(10);
// start sensor as Barometer Active
Wire.beginTransmission((byte)0x60);
Wire.write((byte)0x26); //ctrl_reg
Wire.write((byte)0x01); //start sensor as barometer
Wire.endTransmission();
delay(10);
}
void getdata(byte *a, byte *b, byte *c){
Wire.beginTransmission(0x60);
Wire.write((byte)0x01); // Data_PMSB_reg address
Wire.endTransmission(); //Stop transmission
Wire.requestFrom(0x60, 3); // "please send me the contents of your first three registers"
while(Wire.available()==0);
*a = Wire.read(); // first received byte stored here
*b = Wire.read(); // second received byte stored here
*c = Wire.read(); // third received byte stored here
}
void loop(){
byte aa,bb,cc;
getdata(&aa,&bb,&cc);
Serial.println(aa,HEX); //print aa for example
Serial.println(bb,HEX); //print bb for example
Serial.println(cc,HEX); //print cc for example
delay(5000);
}
The data I receive is : 05FB9 (for example). When I change the register address (see Wire.write((byte)0x01); // Data_PMSB_reg address), I expect the data to change, but it doesn't! Can you explain this to me?
You can find the documentation and datasheets on the NXP website.
I can't properly understand how they communicate with each other. I got communication between Arduino and some other I2C sensors with same communication protocol without any problem.
Your problem is likely due to the fact that the Freescale part requires Repeated-Start I2C communication to do reads. The original Arduino two-wire library (TWI library used by Wire), did not support Repeated-Start.
I know this because I had to rewrite TWI for one of my projects to support Repeated-Start (interrupt driven, both Master and Slave). Unfortunately I've never gotten around to uploading my code, but someone else did essentially the same thing here (at least for Master which is what you need):
http://dsscircuits.com/articles/arduino-i2c-master-library.html
Lose the Wire library and use their I2C library instead.

Resources