arduino-makefile-cli

Migrate from


https://playground.arduino.cc/Learning/CommandLine
https://www.nongnu.org/avr-libc/

install
– avr-gcc (whose package is usually called gcc-avr),
– avr-libc
– avrdude

*GCC: CNU Compiler Collection
*
avr-libc: provide a high quality C library for use with GCC on Atmel AVR microcontrollers
**avrdude: utility to download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers using the in-system programming technique (ISP)

sudo apt-get install gcc-avr avr-libc avrdude
avr-libc avrdude binutils-avr gcc-avr libftdi1 libusb-0.1-4

Look at the Makefile

** Makefile: Makefile是幫助compile的工具,透過Makefile,可以簡化build的流程。特別是當程式愈寫愈大,source file愈來愈多時,更要用Makefile來管理

Makefiles:

$@:目前的目標項目名稱。
$ about the =, :=

linux teminal
sudo usbview
“dmesg | grep tty” to get which port you are using

seems fail to use make in CLI

Synergy – KVM

Migrate form https://cmakerhk.wordpress.com/2018/10/14/synergy-kvm/


https://www.brahma.world/synergy-stable-builds/
https://github.com/synergy

you can install the .msi on the synergy-stable build

for the .deb linux file, I cannot install it with the .deb installer.

Run “sudo apt-get install synergy quicksynergy”

  1. Windows version do not have SSL … so disable it on the Linux side
  2. on the server side, Config the name of your client device
  3. on the client side, config the ip adress of the server
  4. click start on both program. and it should work fine

becareful you should have a pretty go internet connection.

avr-c-marco-define

Migrate from https://cmakerhk.wordpress.com/2018/10/13/marco-define/


#include 
#include 
#include "avr/interrupt.h"

typedef unsigned char BYTE; //8bit 0-255
typedef unsigned int BYTE2;    //16bit 0-65535
typedef unsigned long BYTE4;//32bit 0-4294967295
typedef enum { FALSE, TRUE } bool; // 0 false, 1 true
//Marcos of register

#define F_CPU 16000000UL  // 16 MHz for ATmega328p, UL stand for unsigned integer
#define SETBIT(ADDRESS,BIT)        (ADDRESS |= (1<
//exam ultimate shorthand
/*
 * EIE3105_exam.c
 *
 * Created: 12/4/2017 12:51:11 AM
 * Author : CenzSA12
 */ 

#define F_CPU 16000000UL  // 16 MHz for ATmega328p, UL stand for unsigned integer
#define prescaler 256
#define F_CPU_prescaler 16000000UL/prescaler

#include 
#include 
#include "avr/interrupt.h"

typedef unsigned char BYTE; //8bit 0-255
typedef unsigned int BYTE2;    //16bit 0-65535
typedef unsigned long BYTE4;//32bit 0-4294967295
typedef enum { FALSE, TRUE } bool; // 0 false, 1 true
//Marcos of register

#define SETBIT(ADDRESS,BIT)        (ADDRESS |= (1<



#define ASCIIHex2Num(__ASCII__) (__ASCII__ & 0x0F) + 9*((__ASCII__ & 0x40) >> 6)
#define Num2ASCII_CAP(__Num__) (__Num__ | 0x30) + 7*(__Num__ / 10 )

int main ()
{
  int i = 0;
  char c = 'C';
  i = ASCIIHex2Num ('e');
  printf("%i", i);
  c = Num2ASCII_CAP (i);
  printf ("%c", c);

  return 0;
}



bus-pirate-note

Migrate from https://cmakerhk.wordpress.com/2018/10/13/bus-pirate-note/


Learning Guys

https://github.com/BusPirate/Bus_Pirate
Compiling your own firmware:
http://dangerousprototypes.com/docs/Compile_the_Bus_Pirate_firmware
https://github.com/BusPirate/Bus_Pirate/blob/master/Documentation/building-and-flashing-firmware.md
http://dangerousprototypes.com/docs/Bus_Pirate_101_tutorial

The Bus Pirate firmware defaults to a 115200bps/8/N/1 UART.

Hi Z>m
//show the menu to change the mode
HiZ> ? 
//Show all the command


mode:
HiZ
1-Wire
UART
I2C
SPI
2WIRE
3WIRE
LCD
DIO

http://dangerousprototypes.com/docs/Logic_analyzer_mode
Bus Pirate Logic Analysis mode
http://eecs.oregonstate.edu/education/docs/bus_pirate/How%20To%20Use%20A%20Bus%20Pirate.pdf

https://www.lxtreme.nl/ols/
http://logicsniffer.gadgetfactory.net/index.php?n=LogicSniffer.Download

avr-c-programming-notes

Migrate from https://cmakerhk.wordpress.com/2018/10/13/avr-c-programming/


_BV is only defined in the avr-libc headers. Extracted from avr/sfr_defs.h in avr-libc::::BV=Bit Value

       #define _BV(bit) (1 << (bit))

       TCCR2 = _BV(COM20)|_BV(CTC2)|_BV(CS20);
        DDRD = _BV(PD7);
==
       TCCR2 = (1<



//bit masking
// BM => Bit Mask
#define _BM(bit7, bit6, bit5, bit4, bit3, bit2, bit1, bit0)     \
(                                                               \
    ((bit7 == 7) << (bit7 & 7)) |                               \
    ((bit6 == 6) << (bit6 & 6)) |                               \
    ((bit5 == 5) << (bit5 & 5)) |                               \
    ((bit4 == 4) << (bit4 & 4)) |                               \
    ((bit3 == 3) << (bit3 & 3)) |                               \
    ((bit2 == 2) << (bit2 & 2)) |                               \
    ((bit1 == 1) << (bit1 & 1)) |                               \
    ((bit0 == 0) << (bit0 & 0))                                 \
)

UCSR0A = _BM (RXC0, TXC0, ~UDRE0, ~FE0, ~DOR0, ~UPE0, ~U2X0, ~MPCM0);


#define pinIsSlave 2
#define pinNSS 10
//pin2 is High –> Slave
//pin2 is Low –> Master

#define DDR_SPI DDRB
#define DD_MOSI DDB3
#define DD_MISO DDB4
#define DD_SCK DDB5
#define DD_NSS DDB2

//==========
//pin Master Slave
//MOSI User INPUT
//MISO INPUT User
//SCK User INPUT
//NSS User INPUT

//__enable_interrupt();
void SPI_MasterInit(void);
char SPI_MasterTransmit(char cData);
void SPI_SlaveInit(void);
char SPI_SlaveReceive(void);

void setup() {
pinMode(pinIsSlave, INPUT_PULLUP);
Serial.begin(9600);
Serial.println(“Master/Slave SPI - USART Firmware V1.0”);
Serial.println(“pin2 is High –> Slave || pin2 is Low –> Master”);

//Program Start
if(digitalRead(pinIsSlave)){
//========================= SLAVE ===================
Serial.println(“\n\n====Slave Mode is Selected====”);
pinMode(pinNSS, INPUT);
SPI_SlaveInit();

while(1){
if(digitalRead(pinNSS) == LOW)
Serial.print(SPI_SlaveReceive());
}

}else{
//========================= MASTER ==================
Serial.println(“\n\n====Master Mode is Selected====”);
pinMode(pinNSS, OUTPUT);
SPI_MasterInit();

while(1){
digitalWrite(pinNSS, HIGH);
char a = SPI_MasterTransmit(‘h’);
digitalWrite(pinNSS, LOW);
Serial.print(a);
delay(2000);
}

}
}

void SPI_MasterInit(void){
// Set MOSI and SCK output, all others untouch
DDR_SPI |= (1 << DD_MOSI)|(1 << DD_SCK);

//Enable SPI, Master,
SPCR |= (1 << SPE)|(1 << MSTR);

//SPI0 Clock Rate Select to f_osc/16
SPCR |= (1 << SPR0);
}

char SPI_MasterTransmit(char cData){
//Start Transmission
SPDR = cData;

//wait until Commication complete
while(!(SPSR & (1 << SPIF)));

return SPDR;
//
// SPDR = cData;
// asm volatile(“nop”);
// while (!(SPSR & _BV(SPIF))) ; // wait
// return SPDR;

}

void SPI_SlaveInit(void){
//Set MISO output, all other untouch
DDR_SPI |= (1 << DD_MISO);

//Enable SPI
SPCR = (1 << SPE);
}

char SPI_SlaveReceive(void){
//wait until Commication complete
Serial.print(“I am fucking here”);
while(!(SPSR & (1 << SPIF)));
Serial.println(“Something is here”);

//Start Transmission
return SPDR;
}

void loop() {
// put your main code here, to run repeatedly:

}

linux-install-on-external-hdd

Migrate from https://cmakerhk.wordpress.com/2018/10/13/install-on-external-hdd/


How I made it:

the ubuntu iso only create the boot part –> therefore, it has no OS inside and the file is quite small.

How I fail ::
I use rufus/etcher to burn iso on External HDD, and the installation of the OS require remapping on the memory address, therefore, it crash on these scenaio.

I use one more USB (16GB) to be burnt by rufus, and install that ubuntu on my 1TB external HDD, and this success.

The error message won’t tell you this, you need to go and explore by yourselve.

–> partition software, https://www.partitionwizard.com/ by miniTool
–> Flashing software: rufus/etcher

Many tutorial and youtube won’t help, since they don’t give you the big picture.

It is similar but not the same on flashing with raspberry pi(ubuntu Mate) and ubuntu Desktop

On Ubuntu Mate(pi), you flash the image on to the SD card, and everything is done.. the OS is already installed on the SD card.

However, in ubuntu Desktop, you need to have the installation USB, and a harddisk to make it work.

If needed self-parti:
swap area 512 MB
/home 20000MB
/ the rest of your HDD

will do

ref: https://askubuntu.com/questions/343268/how-to-use-manual-partitioning-during-installation

Hope you can do it. happy Linux

arduino-spi

Migrate from https://cmakerhk.wordpress.com/2018/10/12/arduino-spi/


https://www.microchip.com/wwwproducts/en/ATmega328p
https://www.arduino.cc/en/Reference/SPI

The Arduino Lib is for SPI Master, if you would like to play with SLAVE >> 0) –> to enable SPI module

https://github.com/PaulStoffregen/SPI/blob/master/SPI.h

//master loopback
#include 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  SPI.begin();
}

void loop() {
  // put your main code here, to run repeatedly:

}

void serialEvent(){
//statements
      Serial.print(SPI.transfer(Serial.read()));
}

//unfinished

#define pinIsSlave 2
#define pinNSS 10
//pin2 is High --> Slave
//pin2 is Low  --> Master

#define DDR_SPI DDRB
#define DD_MOSI DDB3
#define DD_MISO DDB4
#define DD_SCK  DDB5
#define DD_NSS  DDB2

//==========
//pin   Master    Slave
//MOSI  User      INPUT
//MISO  INPUT     User
//SCK   User      INPUT
//NSS   User      INPUT

//__enable_interrupt();
void SPI_MasterInit(void);
char SPI_MasterTransmit(char cData);
void SPI_SlaveInit(void);
char SPI_SlaveReceive(void);

void setup() {
  pinMode(pinIsSlave, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Master/Slave SPI - USART Firmware V1.0");
  Serial.println("pin2 is High --> Slave || pin2 is Low  --> Master");

  //Program Start
  if(digitalRead(pinIsSlave)){
   //========================= SLAVE ===================
   Serial.println("\n\n====Slave Mode is Selected====");
   SPI_SlaveInit();
  }else{
   //========================= MASTER ==================
   Serial.println("\n\n====Master Mode is Selected====");
   pinMode(pinNSS, OUTPUT);
   SPI_MasterInit();

   char a = SPI_MasterTransmit('i');
   Serial.print(a);

  }
}

void SPI_MasterInit(void){
  // Set MOSI and SCK output, all others untouch
  PORTB = 0xFF;
  DDR_SPI = (1 << DD_MOSI)|(1 << DD_SCK);

  //Enable SPI, Master,
  SPCR = (1 << SPE)|(1 << MSTR);

  //SPI0 Clock Rate Select to f_osc/16
  SPCR |= (1 << SPR0);
}

char SPI_MasterTransmit(char cData){
  //Start Transmission
  SPDR = cData;

  //wait until Commication complete
  while(!(SPSR & (1 << SPIF)));

  return SPDR;
//
//    SPDR = cData;
//    asm volatile("nop");
//    while (!(SPSR & _BV(SPIF))) ; // wait
//    return SPDR;

}

void SPI_SlaveInit(void){
  //Set MISO output, all other untouch
  DDR_SPI = (1 << DD_MISO);

  //Enable SPI
  SPCR = (1 << SPE);  
}

char SPI_SlaveReceive(void){
  //wait until Commication complete
  while(!(SPSR & (1 << SPIF)));

  //Start Transmission
  return SPDR;
}










void loop() {
  // put your main code here, to run repeatedly:

}


ref:
http://www.gammon.com.au/forum/?id=10892&reply=1#reply1

Using SPI on RPi

Migrate from https://cmakerhk.wordpress.com/2018/10/08/using-spi-on-rpi/


1
2
sudo raspi-config
------to turn the SPI on----------

Problem I have got:
“If the SPI driver was loaded, you should see the device /dev/spidev0.0”
BUT WHAT THE FUCK I DON”T HAVE THAT =.= …
http://neophob.com/2012/08/raspberry-pi-enable-the-spi-device/ (useless)
http://www.brianhensley.net/2012/07/getting-spi-working-on-the-raspberry-pi.html (USELESS)
=.= The Rpi-update will take you to the latest AND unstable version of kernal

So the official command should be
sudo apt-get update;
sudo apt-get install –reinstall raspberrypi-bootloader raspberrypi-kernal

To check your firmware:
$ uname -a
$ cat /proc/version

IT SHOULD BE VERY EASY TO turn SPI on, if everything is not right … don’t structgle. try flashing other kernal … since kernal problem is not that easy to handle >>>>> actually is impossible to handle

note:
I have tried to move the missing /dev/spidev0.0 and /dev/spidev0.1 file to that raspberry pi –>>
and hoping it will work fine… and it doesn’t work.

SPI workable kernal: Linux version 4.9.35-v7+
SPI not workable kernal: Linux version 4.14.73-v7+

Ref: https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md

i2c
On bash:
i2cdetect

Raspberry pi:Skills

Migrate from https://cmakerhk.wordpress.com/2018/10/08/raspberry-pi-skills/


accessing with Serial >,<

Setting up wifi connection with CMD


Accessing GPIO
On SHELL/BASH
https://luketopia.net/2013/07/28/raspberry-pi-gpio-via-the-shell/

On C++
Wiring Pi
http://atceiling.blogspot.com/2014/02/raspberry-pi-wiringpi-gpio.html

On python

  • GPIO Zero library ::gpiozero ::https://gpiozero.readthedocs.io/en/stable/
  • RPi.GPIO::https://pypi.org/project/RPi.GPIO/
  • WiringPi-Python-----Unofficial Python-Wrap
  • RPIO
  • pigpio
Other Lang: https://elinux.org/RPi_GPIO_Code_Samples

pinout: https://pinout.xyz/pinout/pin8_gpio14
It seems have a little messy on the pin arrangement on the Pi

root@raspberrypi:/sys/class/gpio# pinout
,--------------------------------.
| oooooooooooooooooooo J8     +====
| 1ooooooooooooooooooo        | USB
|                             +====
|      Pi Model 3B V1.2          |
|      +----+                 +====
| |D|  |SoC |                 | USB
| |S|  |    |                 +====
| |I|  +----+                    |
|                   |C|     +======
|                   |S|     |   Net
| pwr        |HDMI| |I||A|  +======
`-| |--------|    |----|V|-------'

Revision           : a02082
SoC                : BCM2837
RAM                : 1024Mb
Storage            : MicroSD
USB ports          : 4 (excluding power)
Ethernet ports     : 1
Wi-fi              : True
Bluetooth          : True
Camera ports (CSI) : 1
Display ports (DSI): 1

J8:
   3V3  (1) (2)  5V
 GPIO2  (3) (4)  5V
 GPIO3  (5) (6)  GND
 GPIO4  (7) (8)  GPIO14
   GND  (9) (10) GPIO15
GPIO17 (11) (12) GPIO18
GPIO27 (13) (14) GND
GPIO22 (15) (16) GPIO23
   3V3 (17) (18) GPIO24
GPIO10 (19) (20) GND
 GPIO9 (21) (22) GPIO25
GPIO11 (23) (24) GPIO8
   GND (25) (26) GPIO7
 GPIO0 (27) (28) GPIO1
 GPIO5 (29) (30) GND
 GPIO6 (31) (32) GPIO12
GPIO13 (33) (34) GND
GPIO19 (35) (36) GPIO16
GPIO26 (37) (38) GPIO20
   GND (39) (40) GPIO21

For further information, please refer to https://pinout.xyz/

Comparision on the speed of the GPIO on different lang
http://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/

ESP8266:ESP-Link

Migrate from https://cmakerhk.wordpress.com/2018/10/05/esp8266-esp-link/


https://github.com/jeelabs/esp-link
—> This is the github file

The real image is hidden (I don’t know why ) in Flashing.md and under “Initial serial flashing”
the release: https://github.com/jeelabs/esp-link/releases

The link above is the real image… and flash it with the nodeMCU flasher

If you don’t know the relationship between the nodeMCU and ESP8266 you can refer to my previous article. :https://cmakerhk.wordpress.com/category/hardware/esp/