Pages

Tuesday, 22 May 2018

Uploading and Receiving Data from Cloud using ESP8266



Step1:
Create an Account in www.cloudmqtt.com





Step2
Create an instance which will be used in the program to publish data to the cloud.









Step3:
Select the Instance name (test_1) and use the details of the same in the code.






Include the details in the code:


Step4:
Inorder to send a message to the CloudMQTT, include the line
 client.publish("topic_name", "Message");





The message sent will appear in the WEBSOCKET UI of the specified Instance.




Step5:
To send data from CloudMQTT ,include the line 
client.subscribe("Topic_name");



The same Topic_name should be used in the WEBSOCKET UI as specified in the code while sending the message

Step6:
The following code prints the received data from the cloud in the Serial Monitor:






Step7:
The final code establishing connecting between ESP8266 and Cloud MQTT is given below:

# include <ESP8266WiFi.h>
#include <PubSubClient.h>
 const char* ssid = "Your WiFi Username";
const char* password = "Wifi Password";
const char* mqttServer = "m10.cloudmqtt.com"; // Details from the instance created
const int mqttPort = 18015;
const char* mqttUser = "dswvkhpd";
const char* mqttPassword = "rqVQavi1Y-p9";
WiFiClient espClient;
PubSubClient client(espClient);

void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) // Connecting ESP8266 to WiFi
 {
    delay(500);
    Serial.println("Connecting to WiFi..");
   
 }
 Serial.println("Connected to the WiFi network");
 client.setServer(mqttServer, mqttPort);
 client.setCallback(callback);
 while (!client.connected()) // Connecting to CloudMqtt
 {
    Serial.println("Connecting to MQTT...");

    if (client.connect("ESP8266Client", mqttUser, mqttPassword ))
   {
   Serial.println("connected"); 
    }
    else
    {
      Serial.print("failed with state ");
      Serial.print(client.state());
      delay(2000);
    }
 }

  client.publish("test1", "Hello from RDL_IOT"); // Sending message to Topic "test1"
  client.subscribe("test"); //Receives message sent to the topic "test"
}

void callback(char* topic, byte* payload, unsigned int length) // This function is used to         //print the incoming data sent to the topic "test"
{
  uint8_t s;
  Serial.print("Message arrived in topic: ");
  Serial.println(topic);

  Serial.print("Message:");
  for (int i = 0; i < length; i++)
  {
    s= payload[i];
    Serial.write(s); 
  }
}

void loop()
{
  client.loop();
}




FOR ESP8266 BOARD : CLICK HERE

Thursday, 26 April 2018

ARM-LPC1768-Interface a simple Switch and display its status through Relay, Buzzer and LED.


Program:
/* Connections */
/* Switch = P2.5
 * led = P2.0
 * buzzer = P2.1
 * relay = P2.2
 */

#include <lpc17xx.h>
#include "blink.h"
 
#define Switch 5
#define Led    0
#define buzzer 1
#define relay  2

/* start the main program */
int main()
{
uint32_t switchStatus;

/* Initialize the output pins for led, buzzer and relay */
GPIO_Init_Output(buzzer);
GPIO_Init_Output(Led);
GPIO_Init_Output(relay);

/* Initialize the input pin */
GPIO_Init_Input(Switch);

LED_OFF(Led);
LED_OFF(buzzer);
LED_OFF(relay);

while(1)
{
/* Turn On all the leds and wait for one second */
switchStatus = GPIO_Read(Switch);  /* Read the switch status */

if(switchStatus == 1)               /* Turn ON/OFF LEDs depending on switch status */

LED_ON(Led);
LED_ON(buzzer);
LED_ON(relay);
}
else
{
LED_OFF(Led);
LED_OFF(buzzer);
LED_OFF(relay);
}     
}
}


Hardware Connection
Connect P2.5 to switch (development board)
Connect P2.0 to led (development board)
Connect P2.0 to led (development board)
Connect P2.0 to led (development board)

Output
When the switch is pressed LED is ON, buzzer is ON and relay is ON.
When the switch is not pressed LED is OFF, buzzer is OFF and relay is OFF.

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-1768-LPCDisplay the Hex digits 0 to F on a 7-segment LED with an appropriate delay in between

Program:
/** Connections
  * A(development board) -> P2.0
* B(development board) -> P2.1
* C(development board) -> P2.2
* D(development board) -> P2.3
* E(development board) -> P2.4
* F(development board) -> P2.5
* G (development board) -> P2.6
* DIG1/DIG2/DIG3/DIG4(devp board) -> P2.7
  */

#include <lpc17xx.h> 
#include "7segment.h"
#include "delay.h"

/* Initialize the character to be displayed on the 7 segment display */
uint8_t ch[] = {'0', '1', '2', '3', '4', '5', '6', '7',
              '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

uint8_t i = 0;

/* start the main program */   
int main()

uint8_t data;

/* Initialize the 7 Segment display */
//A,B,C,D,E,F,G,DIG
  SEG_INIT(2,3,4,5,6,7,8,9);

  while(1)
  {
    for(i = 0; i < 16; i++)
{
switch(ch[i])
{
case '0' : data = 0x40; break;
case '1' : data = 0x79; break;
case '2' : data = 0x24; break;
case '3' : data = 0x30; break;
case '4' : data = 0x19; break;
case '5' : data = 0x12; break;
case '6' : data = 0x02; break;
case '7' : data = 0x78; break;
case '8' : data = 0x00; break;
case '9' : data = 0x18; break;
case 'A' : data = 0x08; break;
case 'B' : data = 0x00; break;
case 'C' : data = 0x46; break;
case 'D' : data = 0x40; break;
case 'E' : data = 0x06; break;
case 'F' : data = 0x0E; break;
default  : data = 0x40; break;
}

/* Display the character on seven segment LED */
Display(data);
DELAY_ms(50);
}
  }
}

Hardware Connection
Connect R5 (development board) to P2.0 (segment ‘a’)
Connect R6 (development board) to P2.1 (segment ‘b’)
Connect R7 (development board) to P2.2 (segment ‘c’)
Connect R8 (development board) to P2.3 (segment ‘d’)
Connect R9 (development board) to P2.4 (segment ‘e’)
Connect R10 (development board) to P2.5 (segment ‘f’)
Connect R11 (development board) to P2.6 (segment ‘g’)
Connect DIG /DIG2/DIG3/DIG4 (development board) to P2.7


Output
The 7Segment Display starts displaying the characters from 0 – F.

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768-Demonstrate the use of an external interrupt to toggle an LED On/Off

Program:
/* Connections
 * Connect P2.11 to switch(development board)
 * Connect P2.3 to led(development board)
 * When switch is pressed led = ~led
 */

#include <lpc17xx.h> 
#include "ExtInt.h"

/* LED assigned to P2.3, pin number can be changed */
#define    LED    3   

/* Interrupt Handler */
void EINT1_IRQHandler(void)
{
/* Toggle the LED (P2_3) */
GPIO_PinToggle(LED);
}
     
int main()
{
/* Initialize the external interrupt 1 */
ExtInt_Init();

/* Initalize the GPIO pin as output */
GPIO_Init(LED);

/* Enable the EINT1 interrupts */
  NVIC_EnableIRQ(EINT1_IRQn);               

/* Infinite loop */
while(1)
{
// Do nothing
}     
}

Hardware Connection
Connect P2.11 to switch (development board)
Connect P2.3 to led (development board)

Output
When switch is pressed led = ~led

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768-Using the Internal PWM module of ARM controller, generate PWM and vary its duty cycle


Program:
/**
  * @brief Generate PWM on P2.0
  * DutyCycle varies from 0-100% and back from 100%- 0%.
  */

#include <lpc17xx.h>
#include "pwm.h"

/* variable to hold dutycycle value */
uint8_t dutyCycle;

int main(void)
{
/* Initialize the PWM Peripheral */
  PWM_Init();

/* Infinite loop */
while(1)
{
/* Increase dutycycle for from 0 to 100% */
for(dutyCycle = 0; dutyCycle < 100; dutyCycle++)
{
/* Set the PWM */
PWM_Set_Duty(dutyCycle);

/* set delay */
DELAY_ms(5);
}

for(dutyCycle = 100; dutyCycle > 0; dutyCycle--)
{
/* Set the PWM */
PWM_Set_Duty(dutyCycle);
/* set delay */
DELAY_ms(5);
}
}
}

Hardware Connections:
Connect positive of the CRO to pin P2.0
Connect negative of the CRO to the GND (development board)

Output:
A square wave is seen on CRO who pulse width varies from 0% - 100% and from 100% - 0%

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

Wednesday, 18 April 2018

ARM-LPC1768-Interface a 4x4 keyboard and display the key code on an LCD


ARM-Interface a 4x4 keyboard and display the key code on an LCD


Program
 /** @brief When key is pressed, corresponding key is displayed on LCD
* @Connections :
  * D0 (LCD) -> P1.19
* D1 (LCD) -> P1.20
* D2 (LCD) -> P1.21
* D3 (LCD) -> P1.22
* D4 (LCD) -> P1.23
  * D5 (LCD) -> P1.24
  * D6 (LCD) -> P1.25
  * D7 (LCD) -> P1.26
  * RS (LCD) -> P1.27
* EN (LCD) -> P1.28
  * C1 (Keypad) -> P2.0
* C2 (Keypad) -> P2.1
* C3 (Keypad) -> P2.2
* C4 (Keypad) -> P2.3
  * R1 (Keypad) -> P2.4
* R2 (Keypad) -> P2.5
* R3 (Keypad) -> P2.6
* R4 (Keypad) -> P2.7
*/

#include <lpc17xx.h>
#include "LCD.h"
#include "keypad.h"

char keypad(void);
char c;

/* start the main program */
int main()
{
/* Initialize the GPIO pins for LCD */
/* PORT1 D0,                D7, RS, EN */
LCD_Init(19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
delay(100);

/* Initialize the GPIO pins for Keypad */
/* PORT2    C1         R1         */
Keypad_Init(0, 1, 2, 3, 4, 5, 6, 7);
delay(100);

/* Set LCD parameters like contrast, backlight, cursor position etc */
CMD_WRT(0x38); 
CMD_WRT(0x0f);                         
CMD_WRT(0x06); 
CMD_WRT(0x01);

delay(100);

CMD_WRT(0X01);
CMD_WRT(0X80);
LCD_WRT("----RDL--");
CMD_WRT(0XC0);

  while(1)
  {
/* get the key pressed */
c = keypad();

/* write the key to LCD */
DATA_WRT(c);

delay(100);
}
}

Hardware Connection
D0 (LCD) -> P1.19
D1 (LCD) -> P1.20
D2 (LCD) -> P1.21
D3 (LCD) -> P1.22
D4 (LCD) -> P1.23
D5 (LCD) -> P1.24
D6 (LCD) -> P1.25
D7 (LCD) -> P1.26
RS (LCD) -> P1.27
EN (LCD) -> P1.28             
                                C1 (Keypad on development board) -> P2.0
C2 (Keypad on development board) -> P2.1
C3 (Keypad on development board) -> P2.2
C4 (Keypad on development board) -> P2.3
R1 (Keypad on development board) -> P2.4
R2 (Keypad on development board) -> P2.5
R3 (Keypad on development board) -> P2.6
R4 (Keypad on development board) -> P2.7
Output
When the Key is pressed, Corresponding key is displayed on the LCD. For example, if key ‘1’ is pressed, on LCD it should show “Key Pressed is 1”


 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768-Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.

Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.


Program

/**
  * @brief Run steeper motor Clockwise when switch = 1 and reverse direction when switch = 0
  * @Connection
  * SDA  ------------------>  P2.0
  * SCL  ------------------>  P2.1
  * TX   ------------------>  P2.2
  * RX   ------------------>  P2.3
* 5V(FRC) --------------->  5V on board (without this, stepper motor produces jerk)
  * switch ---------------->  P2.5
  */

#include <lpc17xx.h> 
#include "stepper.h"
#include "blink.h"

#define    Switch  5       /* switch is connected to P2.5 */
uint16_t i;

int main()
{
  uint32_t switchStatus;

  /* Configure GPIO pins for steeper motor windings */
  Stepper(0,1,2,3);

  while(1)
  {
    /* Turn On all the leds and wait for one second */
    switchStatus = GPIO_Read(Switch);  /* Read the switch status */
 
    if(switchStatus == 1)    /* If switch == 1, motor runs in clockwise direction */
    { 
      /* for sometime run tghe motor in forward direction */
      for(i = 10; i > 0; i--)
        Motor_Forward_Direction();
    }
    else
    {
      /* for sometime run tghe motor in forward direction */ 
      for(i = 10; i > 0; i--)
        Motor_Reverse_Direction();
    }
  }
}
Hardware Connection
ENA (L298 driver) to 5V
IN1 (L298 driver) to P2.1
IN2 (L298 driver) to P2.2
ENB (L298 driver) to 5V
IN4 (L298 driver) to P2.3
IN5 (L298 driver) to P2.4
VMS (L298 driver) to Vin (12Volts, development board)
GND (L298 driver) to
FRC of Stepper Motor to FRC of L298 driver
Output
Stepper Motor runs in forward direction for some time and runs in reverse direction in some time. This repeats continuously.

FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE