Prince Mustang's arduino learning notes

Keywords: bluetooth arduino

This blog is used to record and share the problems and things needing attention in the process of learning arduino. I am a novice. If you have any questions, you are welcome to criticize and correct

Related contents: arduino UNO/arduino nano/Arduino MKR1000 / Bluetooth HC05/HC06/PIR sensor

Arduino board

Arduino UNO

This is too basic. Please fill it up when you have time

Arduino nano

When I was doing nano, I encountered a bug that made me doubt my life. It was that after the nano board was connected, it could not be recognized in the compiler. Then open my computer - Management - Device Manager - port and find a CH340 device in it, but click it to find that "the device works abnormally because windows cannot load the driver required for this device". It's useless to update the driver manually. It shows that there is a problem with the driver and it can't be installed. It seems that this problem mainly lies in win10. There are two main solutions available online to solve this problem

  1. Manual download driver
    http://www.wch.cn/download/CH341SER_EXE.html
    Some people say that during installation, when there is no connection board, click Install to display that after the pre installation is completed, click Install on the connection board to display that the installation is completed

  2. Disable driver forced signing
    https://jingyan.baidu.com/article/624e74594dbc8d34e8ba5aa6.html

Neither of these solutions seems to solve my problem. I later fooled around for a while, and he suddenly got better:). The problem that bothered me for a week suddenly solved itself. I can only vaguely remember the operation at that time. It seems that I unloaded the driver first, and then I can see the device in my computer - Management - Device Manager - universal serial bus controller. Start a mess from that place and it's all right. If someone really can't solve this problem, you can break the jar and try it.

Arduino MKR1000

Arudino MKR1000 is an Arduino board with WIFI module. The price is quite expensive. I borrowed it from the tutor's laboratory. It seems that there are still a small number of domestic products, and there are no cheap domestic products. Here are some points to note:

  1. According to the official website, the working voltage of MKR board is 3.3V, and 5V I/O port will damage the board. I don't quite understand what this means. The board provides 5V power supply. Can't the board accept normal digital signals?
  2. I want to connect a Bluetooth module to the MKR board, so I use the UART serial port of the board. However, there is a problem that Bluetooth does not respond. After a search on google, I found that the serial command of MKR is specially used for the wired port connected to the computer. The hardware serial port needs to be controlled by Serial1 instruction.
  3. I use the WIA platform suggested by the teacher on the dashboard https://dashboard.wia.io/spaces
    Guidance is provided on the website https://developers.wia.io/things/mkr1000
    Code example:
#include <WiFi101.h>
#include <ArduinoJson.h>
#include <ArduinoHttpClient.h>


const char WIFI_SSID[] = "your-wifi-ssid"; // WiFI ssid 
const char WIFI_PASS[] = "your-wifi-password"; //WiFI password

// get this from the wia dashboard. it should start with `d_sk`
const char* device_secret_key = "your-device-secret-key";

WiFiClient client;
int status = WL_IDLE_STATUS;

// Wia API parameters
char server[] = "api.wia.io";
char path[] = "/v1/events";
int port = 80;

StaticJsonDocument<200> jsonBuffer;
HttpClient httpClient = HttpClient(client, server, port);
JsonObject root = jsonBuffer.to<JsonObject>();

void setup() {

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Starting WiFI connection to Wia!.");
 
 // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(WIFI_SSID);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(WIFI_SSID, WIFI_PASS);

    // wait 5 seconds for connection:
    delay(5000);
  }
  
}

void loop() {
  root["name"] = "hello-wia";
  root["data"] = "";

  // if you get a connection, report back via serial:
  if (client.connect(server, port)) {

    postToWia(root);

  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
   delay(3000); // Wait for 3 seconds to post again
}

void postToWia(JsonObject& data){
    String dataStr = "";
 		serializeJson(data, dataStr);
    httpClient.beginRequest();
    httpClient.post(path);
    httpClient.sendHeader("Content-Type", "application/json");
    httpClient.sendHeader("Content-Length", dataStr.length());
    httpClient.sendHeader("Authorization", "Bearer "  + String(device_secret_key));
    httpClient.beginBody();
    httpClient.print(dataStr); 
    httpClient.endRequest();
 
  }

device

Bluetooth hc05 & hc06

To be added

PIR sensor

To be added

Posted by chinto09 on Thu, 07 Oct 2021 00:02:56 -0700