Advance C/C++ lang topics

// Here we can see that more than one variables
// are being used without reporting any error.
// That is because they are declared in the
// different namespaces and scopes.
#include <iostream>
using namespace std;

// Variable created inside namespace
namespace first
int val = 500;

// Global variable
int val = 100;

int main()
// Local variable
int val = 200;

// These variables can be accessed from
// outside the namespace using the scope
// operator ::
cout << first::val << ‘\n’;

return 0;

C++[] –> namespace is like a named-scope, so you can use it kind of like everywhere

CNU library

More about C/C++ library


WSL (Windows Subsystem Linux)

on Windows 10: install via store

on Powershell: enter the command

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux


To run linux command on cmd::::

wsl ls -la

wsl xxxxxxx


To run windows command on WSL:::::

cmd.exe /C dir


PING.exe , ipconfig.exe

(( this depended on if the command has file extension or a bat file.


Basic thing, telegram on NodeMCU

Example used: HTTPSRequest

HTTP over TLS (HTTPS) example sketch

This example demonstrates how to use
WiFiClientSecure class to access HTTPS API.
We fetch and display the status of
esp8266/Arduino project continuous integration

only RSA certificates
no support of Perfect Forward Secrecy (PFS)
TLSv1.2 is supported since version 2.4.0-rc1

Created by Ivan Grokhotkov, 2015.
This example is in public domain.

get Info of bot:<YOUR-BOT-TOKEN>/getme




On the NodeMCU: Since it is HTTPS –> I cannot find a way to used it with AT COMMAND

Programming to NodeMCU:

–>fingerprint[] –> inside the Chrome –> certificate –> detail –> thumb print


GPRS A9 Module AT Command list





Test the DNS, and check with terminal

host -a

//Base station location

+CREG: 2,1,”00A0″,”0D37″<\r><\n>

MCC:454 -> HK//

MNC: 12 -> CMHK//

LAC: 160 -> 0xA0

CI:3383 -> 0xD37

Google Cloud AutoML test


Google 機器學習三大服務:AutoML, Cloud ML Engine, ML API 介紹與比較


Cloud AutoML Vision Object Detection

With my training data:

Getting Started on Sipeed MAIX M1
Link of the product.

Sipeed MAIX M1 is a SoC of the kendryte K210:
Sipeed is AI enabler

When if ship, it has Maxipy flashed inside the SoC. Connect to the PC via USB cable, connect with UART, putty (success)

MaixPy 是将 Micropython 移植到 K210( 一款64位双核带硬件FPU和卷积加速器的 RISC-V CPU, ) 的一个项目. —-> source code

About the chip:

About the M1 SoC:

—-> doc from the sipeed

FreeRTOS on Arduino

#include // add the FreeRTOS functions for Semaphores (or Flags).

//===create task===
void TaskBlink( void *pvParameters );
void TaskAnalogRead( void *pvParameters );
void TaskDigitalRead( void *pvParameters );

void setup(){

//===create task event
, (const portCHAR *)”Blink” // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, 2 // Priority, with 3 (configMAX_PRIORITIES – 1) being the highest, and 0 being the lowest.
, NULL );


void loop(){}

//====everything is in task
void TaskAnalogRead(void *pvParameters) // This is a task.
(void) pvParameters;

Reads an analog input on pin 0, prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.

for (;;)
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
vTaskDelay(1); // one tick delay (15ms) in between reads for stability

#include // add the FreeRTOS functions for Semaphores (or Flags).

// Declare a mutex Semaphore Handle which we will use to manage the Serial Port.
// It will be used to ensure only only one Task is accessing this resource at any time.
SemaphoreHandle_t xSerialSemaphore;

void setup(){
// Semaphores are useful to stop a Task proceeding, where it should be paused to wait,
// because it is sharing a resource, such as the Serial port.
// Semaphores should only be used whilst the scheduler is running, but we can set it up here.
if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created.
xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port
if ( ( xSerialSemaphore ) != NULL )
xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by “Giving” the Semaphore.

so… to check

// See if we can obtain or “Take” the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 );
–> will return pdTRUE/pdFALSE
xSemaphoreGive( xSerialSemaphore ); // Now free or “Give” the Serial Port for others.

if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
// We were able to obtain or “Take” the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don’t want it getting stolen during the middle of a conversion.
// print out the value you read:

xSemaphoreGive( xSerialSemaphore ); // Now free or “Give” the Serial Port for others.

//==end of the example of the arduino freeRTOS

Flow of doing that:
– Task function declaration
– create task in the setup
– write the task function

Generally in FreeRTOS

int main(void){
prvSetupHardwar(); //perform hardware setup
//create task here
vTaskStartScheduler(); /start the created tasked
return 0;

the naming of the FreeRTOS
c: char, s: short(int16_t), l: long(int32_t), x: BaseType_t
uc: unsigned char(uint8_t), pc: pointer2char

pdTRUE, pdFALSE: 1,0
pdPASS, pdFAIL: 1,0

For Task Management

ATmel studio, ASF compare, HAL vs HPL

There are few people talk about the structure of the atmel studio code set.

I look through the library and the document and give the following result.

Advanced Software Framework(ASF) is the framwork used by Mircochip for Atmel product

ASF4 must be used in conjunction with Atmel START, which replaces the ASF Wizard of ASF3.

After configuring in the Atmel START, you can see a list of library inside the folder.

列出磁碟區 Windows 的資料夾 PATH
磁碟區序號為 EE0C-64C1
│ ├─Config
│ ├─Device_Startup
│ ├─examples
│ ├─hal
│ │ ├─include
│ │ ├─src
│ │ └─utils
│ │ ├─include
│ │ └─src
│ ├─hpl
│ │ ├─adc
│ │ ├─core
│ │ ├─dmac
│ │ ├─gclk
│ │ ├─mclk
│ │ ├─osc32kctrl
│ │ ├─oscctrl
│ │ ├─pm
│ │ ├─port
│ │ ├─rtc
│ │ ├─sercom
│ │ ├─systick
│ │ ├─tc
│ │ └─wdt
│ └─hri
│ ├─include
│ ├─src
│ └─utils
│ ├─include
│ └─src
│ ├─adc
│ ├─core
│ ├─dmac
│ ├─gclk
│ ├─mclk
│ ├─osc32kctrl
│ ├─oscctrl
│ ├─pm
│ ├─port
│ ├─rtc
│ ├─sercom
│ ├─systick
│ ├─tc
│ └─wdt

atmel_start_pins.h –> let you find the name of the pin and use it in the program –> \param[in] pin The pin number for device, (const uint8_t pin)

(if middleware is used, it will be the toppest model)
Three main word appear:
• Hardware Abstraction Layer – HAL
Naming convention: HAL functions start with usecase_, for example: adc_dma_driver

• Hardware Proxy Layer – HPL
Naming convention: HPL functions start with _usecase_, for example: _usart_async_init()

• Hardware Register Interface – HRI
accessing the register.

PS, in the utils, it has list, marco, ringbuffer for you to use

Install uPython on NodeMCU

highly Reference to this website



About the ESPtool

pip install esptool

inWindows, run as python module

python -m esptool xxxxxxxx


uPython for ESP8266


>>> import machine
>>> pin = machine.Pin(16, machine.Pin.OUT)
>>> pin.on()

the help has the procedure to connect to the internet

import os
os.listdir() –> show the current file


The special variable _ –> store the last result

it has uos module for the os module

ctrl D is for restart
ctrl E is paste Mode, essentially turns off the auto-indent feature
ctrl A is in Raw REPL mode
Raw Mode
Raw mode is not something that a person would normally use. It is intended for programmatic use. It essentially behaves like paste mode with echo turned off.

Raw mode is entered using Ctrl-A. You then send your python code, followed by a Ctrl-D. The Ctrl-D will be acknowledged by ‘OK’ and then the python code will be compiled and executed. Any output (or errors) will be sent back. Entering Ctrl-B will leave raw mode and return the the regular (aka friendly) REPL


ampy run –no-output
ampy run -n

–> to run the code on PC