0% found this document useful (0 votes)
4 views6 pages

Arduino Key Words

This instruction manual provides guidelines for connecting and using the NodeMCU ESP8266 Wi-Fi module, emphasizing safety precautions and proper connection techniques. It includes a list of programming keywords and their syntax for Arduino, along with examples and descriptions for various functions. Additionally, it outlines MQTT topics for Thingsboard and details the events and return codes for the Paho MQTT client in Python.

Uploaded by

bhanubhanu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Arduino Key Words

This instruction manual provides guidelines for connecting and using the NodeMCU ESP8266 Wi-Fi module, emphasizing safety precautions and proper connection techniques. It includes a list of programming keywords and their syntax for Arduino, along with examples and descriptions for various functions. Additionally, it outlines MQTT topics for Thingsboard and details the events and return codes for the Paho MQTT client in Python.

Uploaded by

bhanubhanu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Instruction Manual

-Think before you connect.

"No one gets a sudden rise, not even the sun, it takes time to rise to the peak of success”
- Edmund Hillary
Instructions
-Think
Think twice before you connect

• Do not open the starter kit until instructed


• All the boards in the kits are tested.
• Follow the instruction carefully while connecting peripherals on breadboard
• Do not place Node MCU board on metallic surface (Specially on Laptop)
• Do not short 5v or 3.3 v and Ground.
• Cross check the connection on the breadboard before connecting NodeMCU.
NodeMCU

ESP8266 Wi-Fi Module


• ESP8266 is a self contained SOC
• Integrated TCP/IP protocol stack that can give any access to your Wi Wi-Fi network
• It offers a complete and self-contained
contained Wi-Fi
Wi networking solution
• Is capable of either hosting an application or offloading all Wi-Fi
Fi networking functions from another application processor.
• High degree of on-chip integration
• Powerful enough on-board
board processing and storage capability
• To be integrated with the sensors and other application specific devices through its GPIOs

Figure: Node MCU Pin outs.

I hear and I forget. I see and I remember. I do and I understand.


-Confucius
List of Key words
Keywords Syntax Example Description
int int variable_name; int m; // int m=8 To define integer numbers. (16 bits in size)
float float variable_name; float p; // float p=5.035 to define floating point numbers(32 bits )
String string variable_name; string n; // n="college" to define array of characters
boolean booleanvariable_name; boolean b;// b=1 or 0 defines simple logical true/false(high or low)
Data char charvariable_name; char p; //p='x' To define characters (signed or unsigned)
types byte bytevariable_name; byte r; unsigned number from 0-255
array arrayvariable_name[size]; int array a[10];// 'a' can store 10 collection of identical elements of same type
elements from 0 to 9
pinMode() pinMode(Var1,OUTPUT/INPUT) pinmode(ledpin ,OUTPUT); Configures the specified pin to behave either
pinmode(13, INPUT); as an input or output
digitalRead() digitalRead(pin); int v1=12; Reads the value from a specified digital pin ,
Val= digitalRead(v1); either HIGH or LOW
digitalWrite() digitalWrite(pin, value); digitalWrite(13, HIGH); Write HIGH or LOW value to digital pin

analogRead() analogRead(pin); int m=analogRead(A0); Reads the analog value from a specified
int n=analogRead(A1); analog pin(A0-A5)
analogWrite() analogWrite(pin); intm=analogWrite(A0); Write the analog value from a specified
int n=analogWrite(A1); analog pin(A0-A5)
delay() delay(value); delay(1000); //one sec dealy Pauses the program for the amount of time
millis(value); millis(1000); //one milli sec specified
micros(value); dealy
micros(1000); //one micro sec
dealy
Map() map(variable, alow, ahigh,mlow ,mhigh); y=map(x,0,1023,1,200); Re-maps a number from one range to
another
[Link]() [Link](baud rate) [Link](9600) Sets the data rate in bits per second (baud)
for serial data transmission.(9600,14400 etc)
[Link](78) //gives 78 Prints data to the serial port as human
[Link]() [Link](data) [Link]("college") //prints readable ASCII text
College
Intv=3; [Link](v) // prints 3
Prints the value 56 fallowed by a carriage
[Link]() [Link]() [Link](56); return character(ASCII 13 or '\n' ) i.e new
line character
[Link]() Variable=[Link](variable) v=[Link](p); Reads incoming serial data
m=[Link](A0);
if ([Link]() > 0) Get the number of bytes (characters)
[Link]() [Link]() { available for reading from the serial port.
intincomingByte = This is data that's already arrived and stored
[Link](); in the serial receive buffer (which holds 64
} bytes)
[Link](45); Writes the binary data to the serial port
[Link]() [Link](val) intbytesent=[Link]("HELLO"); And it will return the number of bytes
written on serial monitor
[Link](78, BIN) gives "1001110"
[Link](val, format) [Link](val, format) [Link](78, OCT) gives "116"
[Link](78, DEC) gives "78"
[Link](78, HEX) gives "4E
int mypins[]={2,4,8}; An array defines the pin numbers of 2,4,8
Arrays Data_typearray_name[size]; which acts as input or output
int myval[4]={2,4,-8,3}; An array initializes four values of type int
[Link](16, 2);//defines for Initializes the interface to the lcd screen
[Link]() [Link](cols,rows); 16,2 LCD display Note: use #include <LiquidCrystal.h> to
interface lcd with arduino
[Link]() [Link](data) [Link]("Hello world") Prints text to LCD
[Link]() [Link](col,row) [Link](5,1)//points to 5th an underscore (line) at the position to which
coloumn,2nd row the next character will be written
[Link]() [Link]() [Link]() Clears the LCD screen
Keywords Syntax Example Description
IPAddress() IPAddress(address) IPAddressip(192, 168, 0, 2); Defines an IP address. It can be used to
declare both local and remote addresses.
[Link](ip); IPAddressip(192, 168, 0, 2); [Link]() allows you to configure a static IP
[Link]() [Link](ip, dns); [Link](ip); address as well as change the DNS, gateway, and
[Link](ip, dns, gateway); subnet addresses on the WiFi shield.
[Link](ip, dns, gateway, DNS: The Domain Name System (DNS) is a
hierarchical decentralized naming system for
subnet);
computers, services, or other resources connected
to the Internet or a private network.
Gateway: A gateway is a network node connecting
two networks that use different protocols.
Subnet: A subnetwork or subnet is a logical
subdivision of an IP network.
[Link]() [Link](); [Link](); Initializes the WiFi library's network settings
[Link](ssid); [Link](ssid); and provides the current status.
[Link](ssid, pass); [Link](ssid, pass); Ssid: Wifi name(Wifi Name)
[Link](ssid, keyIndex, [Link](ssid, keyIndex, key); Pass: password of the ssid(wifi router Pass)
key);
WiFiServer() Server(port); WiFiServer server(80); Creates a server that listens for incoming
port: the port to listen on (int) connections on the specified port.
[Link]() [Link](); [Link](); Return the connection status.

[Link](); [Link]() [Link](); Tells the server to begin listening for incoming
connections.
WiFiClient() WiFiClient() WiFiClient client; Creates a client that can connect to to a
[Link](server, 80) specified internet IP address and port as
defined in [Link]().
[Link]() [Link]() WiFiClient client = Gets a client that is connected to the server
[Link](); and has data available for reading. The
connection persists when the returned client
object goes out of scope;
[Link]() [Link]() [Link](server, 80) Connects to a specified IP address and port.
[Link](ip, port) The return value indicates success or failure.
[Link](URL, port) Also supports DNS lookups when using a
domain name.
ip: the IP address that the client will connect
to (array of 4 bytes)
URL: the domain name the client will connect
to (string, ex.:"[Link]")
port: the port that the client will connect to
(int)

[Link]() [Link]() [Link]() Read the next byte received from the server
the client is connected to
[Link]() [Link]() [Link](“Hello World”) Print data, followed by a carriage return and
[Link](data) newline, to the server a client is connected to.
[Link](data, BASE) Prints numbers as a sequence of digits, each
an ASCII character
[Link]() [Link](); char ssid[] = "yourNetwork"; Gets the SSID of the current network
[Link](wifiAccessPoint) [Link](ssid); wifiAccessPoint: specifies from which
network to get the information
[Link]() [Link](); IPAddressip; Gets the WiFi shield's IP address
ip = [Link]();
[Link](ip);
[Link]() [Link](); long rssi = [Link](); Gets the signal strength of the connection to
[Link](wifiAccessPoint); [Link]("RSSI:"); the router
[Link](rssi);
[Link]() [Link](); IPAddress subnet; Gets the WiFi shield's subnet mask
subnet = [Link]();
[Link]() [Link](); IPAddress gateway; Gets the WiFi shield's gateway IP address.
gateway = [Link]();
[Link]("GATEWAY: ");
[Link](gateway);

[Link]() [Link](); byte encryption = [Link] Gets the encryption type of the current
[Link](wifiAcce ionType(); network
ssPoint); [Link]("Encryption
Type:");
[Link](encryption,HEX);
[Link](); [Link](); byte numSsid = [Link] Scans for available WiFi networks and returns
works(); the discovered number
[Link]("SSID List:");
[Link](numSsid);
[Link](mac); [Link](mac); [Link](mac); Gets the MAC Address of your WiFi shield
[Link]("MAC: "); mac: a 6 byte array to hold the MAC address
[Link](mac[5],HEX);
[Link](":");
[Link](mac[4],HEX);
[Link](":");
[Link](mac[3],HEX);
[Link](":");
[Link](mac[2],HEX);
[Link](":");
[Link](mac[1],HEX);
[Link](":");
[Link](mac[0],HEX);
[Link]() [Link]() [Link]() This function discards any bytes that have
been written to the client but not yet read.
[Link]() [Link](val) Client myClient; Write data to the server the client is
[Link](buf, len) [Link]("Hi there"); connected to. This data is sent as a byte or
series of bytes.
val: a value to send as a single byte (byte or
char)
buf: an array to send as a series of bytes (byte
or char)
len: the length of the buffer
[Link]() [Link]() [Link]() Disconnect the client from the server. It closes
the established connection.
MQTT Topic for Thingsboard

v1/devices/me/telemetry for telemetry data


v1/devices/me/attributes for attributes
v1/devices/me/rpc/request for RPC

Paho MQTT Client in Python

The events and callbacks for the Paho MQTT client are as follows:

• Event Connection acknowledged Triggers the on_connect callback


• Event Disconnection acknowledged Triggers the on_disconnect callback
• Event Subscription acknowledged Triggers the on_subscribe callback
• Event Un-subscription acknowledged Triggers the on_unsubscribe callback
• Event Publish acknowledged Triggers the on_publish callback
• Event Message Received Triggers the on_message callback
• Event Log information available Triggers the on_log callback

In the following table you see all return codes at a glance.

Return Code Return Code Response


0 Connection Accepted
1 Connection Refused, unacceptable protocol version
2 Connection Refused, identifier rejected
3 Connection Refused, Server unavailable
4 Connection Refused, bad user name or password
5 Connection Refused, not authorized

You might also like