clang-markdown

Migrate from https://cmakerhk.wordpress.com/2019/06/10/advance-c-c-lang-topics/,https://cmakerhk.wordpress.com/2019/07/02/c-string-object-vs-c-style-string/,https://cmakerhk.wordpress.com/2019/07/03/pointer-and-address/


// 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
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

https://www.gnu.org/software/libc/manual/html_node/Getopt.html

More about C/C++ library

https://www.tutorialspoint.com/c_standard_library/index.htm

https://www.tutorialspoint.com/cpp_standard_library/index.htm


Two way to manipulate string.

std::string

String Object C-Style Sting
#include "string" #include "cstring" / "string.h"
string myStr = "Hello World"; char myCharr[20] = "Hello World";
str1 = str2; strcpy(charr1, charr2);
str1 += str2; strcat(charr1, charr2);
str.size() strlen(charr)
getline(cin, str); cin.getline(charr, 20); //20 - max len

int myVar = 8; // variable myVar store value
&myVar; //address of myVar
int *myPtr;
myPtr = &myVar; // pointer myPtr store address of myVar
*myPtr; //value of the address pointed by myPtr

myVar &myVar
*myPtr myPtr
value => 23 address => 0x1234
Dynamic array

int size; cin >> size;
int * pz = new int [size]; // dynamic binding, size set at run time

delete [] pz; // free memory when finished

1 2
void swapr(int & a, int & b) // use references { int temp; temp = a; // use a, b for values of variables a = b; b = temp; } swapr(wallet1, wallet2); // pass variables
void swapp(int * p, int * q) // use pointers { int temp; temp = *p; // use *p, *q for values of variables *p = *q; *q = temp; } swapp(&wallet1, &wallet2); // pass addresses of variables
void swapv(int a, int b) // try using values { int temp; temp = a; // use a, b for values of variables a = b; b = temp; } swapv(wallet1, wallet2); // pass values of variables

gprs-a9-log

Migrate from https://cmakerhk.wordpress.com/2019/05/16/gprs-a9-module-at-command-list/


https://wiki.ai-thinker.com/gprs

//

AT+CGDCONT=1,”IP”,”cmhk”<\r><\n>
AT+CGATT=1<\r><\n>
AT+CGACT=1,1<\r><\n>

//

AT+CDNSGIP=”erp.hkite.com”<\r><\n>

Test the DNS, and check with terminal

host -a erp.hkite.com

//Base station location

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

http://www.gpsspg.com/bs.htm

MCC:454 -> HK//http://www.gpsspg.com/bs/mcc.htm

MNC: 12 -> CMHK//http://www.gpsspg.com/bs/mnc.htm

LAC: 160 -> 0xA0

CI:3383 -> 0xD37

google-cloud-compare

Migrate from https://cmakerhk.wordpress.com/2019/04/16/google-cloud-automl-test/


Overview:

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

screenshot:

https://docs.google.com/presentation/d/1KCSoR_aG-yn_vPBYFlLTzQdBAlBcdQgRYp5zdgH5IFA/edit?usp=sharing

Cloud AutoML Vision Object Detection

https://cloud.google.com/vision/automl/object-detection/docs/?_ga=2.244268482.-671499862.1555384491

With my training data: https://cloud.google.com/vision/automl/object-detection/docs/prepare

Getting Started on Sipeed MAIX M1

Migrate from https://cmakerhk.wordpress.com/2019/03/31/getting-started-on-sipeed-maix-m1/


https://item.taobao.com/item.htm?id=578484113485
Link of the product.

Sipeed MAIX M1 is a SoC of the kendryte K210: https://kendryte.com/
Sipeed is AI enabler https://www.sipeed.com/#/

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, ) 的一个项目.
https://micropython.org/
https://maixpy.sipeed.com/zh/
https://github.com/sipeed/MaixPy —-> source code

About the chip:
https://github.com/kendryte/
https://kendryte.com/downloads/

About the M1 SoC: https://maixpy.sipeed.com/assets/M1_pin.png

—-> doc from the sipeed
http://dl.sipeed.com/

arduino-freertos

Migrate from https://cmakerhk.wordpress.com/2019/03/16/freertos-on-arduino/


https://github.com/feilipu/Arduino_FreeRTOS_Library

#include
#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
xTaskCreate(
TaskBlink
, (const portCHAR *)”Blink” // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 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;

/*
AnalogReadSerial
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:
Serial.println(sensorValue);
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:
Serial.println(sensorValue);

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
//======end=====
vTaskStartScheduler(); /start the created tasked
while(1);
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
void

avr-compare

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.

http://www.microchip.com/avr-support/advanced-software-framework-(asf)
https://www.microchip.com/mplab/avr-support/advanced-software-framework
http://ww1.microchip.com/downloads/en/DeviceDoc/50002633A.pdf

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
C:.
├─.atmel-start-backup
├─.atmelstart
├─Config
├─Debug
│ ├─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
├─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

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

upython-nodeMCU

Migrate from https://cmakerhk.wordpress.com/2019/01/20/install-upython-on-nodemcu/


https://docs.micropython.org/en/latest/esp8266/tutorial/intro.html

highly Reference to this website
https://github.com/micropython/micropython

//===========

About the ESPtool

pip install esptool

inWindows, run as python module

python -m esptool xxxxxxxx

//======================

uPython for ESP8266

1
2
3
4
>>> import machine
>>> pin = machine.Pin(16, machine.Pin.OUT)
>>> pin.on()
>>> pin.off()

the help has the procedure to connect to the internet

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

dir()

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

uos.listdir()
uos.mkdir(‘myDir’)
uos.chdir(‘..’)
uos.rmdir(‘myDir’)

//==============adafruit
ampy run –no-output xxx.py
ampy run -n xxx.py

–> to run the code on PC

arduino-memory

Migrate from https://cmakerhk.wordpress.com/2018/12/28/memory-on-arduino/


in Arduino Uno

It has Program Storage Space vs Dynamic memory

“This will store in dynamic memory with each char a byte”
F(“And this will store in program storage space”)

–>> SAVE MORE MORE MORE MEMORY WILL.

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

https://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html

https://playground.arduino.cc/Code/EEPROMWriteAnything

ATMega168 ATMega328P ATmega1280 ATmega2560
Flash
(1 kByte used
for bootloader)
16 kBytes 32 kBytes 128 kBytes 256 kBytes
SRAM 1024 bytes 2048 bytes 8 kBytes 8 kBytes
EEPROM 512 bytes 1024 bytes 4 kBytes 4 kBytes
http://yehnan.blogspot.com/2013/08/arduino.html

http://yehnan.blogspot.com/2014/03/arduinoeeprom.html

https://learn.adafruit.com/memories-of-an-arduino

//======built in support

https://www.arduino.cc/en/Tutorial/EEPROMPut