0730-0800 Absen Pagi hanya absen pagi
0800-0900 >>Buat presentasi untuk RIIM 4 bu Nazarina direncanakan 6-10 Halaman
(baru selesai 3 halaman) perlu ditambah kan program random nerd
0900-1200 Buat program ESP8266 sd card
program untuk mengetes bukan pakai ESP8266 akan tetapi mengunakan ESP32
https://wokwi.com/projects/388854830688347137
perlu diingat pin CS untuk komunikasi SPI adalah pada 5
program dicoba pada ESP8266 yang real sedangkan pin out yang dipergunakan adalah
https://newbiely.com/tutorials/esp8266/esp8266-micro-sd-card
ingat pin CS biasanya mengunakann D8 (jika diarduino IDE akan error) sebenarnya d8 adalah GPIO15 jadi D8 di tulis angka 15 saja
#include <SD.h>
#define CS_PIN 15
String inputSTR,User,Password;
char buf[10] ;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.print("Inisialisasi SD Card..");
if (!SD.begin(CS_PIN)) {
Serial.println("Gagal load SD card.");
return;
}
Serial.println("OK.");
File textFile = SD.open("/Hello.txt");
if (textFile) {
Serial.print("Hello.txt: ");
while (textFile.available()) {
inputSTR=textFile.readString();
User = " ";
Password = " ";
Serial.println(inputSTR);
Serial.println(inputSTR.length());
Serial.println(inputSTR.indexOf(' '));
for (int i = 0; i < inputSTR.indexOf(' '); i++)
{
User.setCharAt(i,inputSTR.charAt(i));
//buf[i] = inputSTR.charAt(i);
// reportString.setCharAt(colonPosition, '=');
//Serial.println(User.charAt(i));
}
for (int i = inputSTR.indexOf(' '); i < inputSTR.length(); i++)
{
Password.setCharAt(i,inputSTR.charAt(i));
Serial.println(Password.charAt(i));
}
Password.trim();
Serial.println(User);
Serial.println(Password);
}
textFile.close();
} else {
Serial.println("error opening wokwi.txt!");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
file diatas ada di ESP8266_sdcard2.uno
untuk aplikasi RISPRO2024 program AMH_ver4_2_ESP8266_ino.ino
#include <ESP8266WiFi.h>
#include <Servo.h>
Servo servo;
int angle = 10;
String kasus = "";
String azum = "ada";
//const char* ssid = "BSN-Trial";
//const char* password = "bsntrial1";
const char* ssid = "GalaxyM126A21";
const char* password = "uhuy";
const char* host = "www.remotecal.com";
WiFiClient client;
const int httpPort = 80;
String url;
unsigned long timeout;
#include <SD.h>
#define CS_PIN 15
String inputSTR,User,Password;
char buf[15] ;
unsigned long previousMillis = 0;
unsigned long interval = 1000;
void setup() {
Serial.begin(115200);
delay(1000);
servo.attach(2); //GPIO2
servo.write(angle);
//pinMode(stepPin,OUTPUT);
//pinMode(dirPin,OUTPUT);
//pinMode(stepPink,OUTPUT);
//pinMode(dirPink,OUTPUT);
Serial.print("Inisialisasi SD Card..");
if (!SD.begin(CS_PIN)) {
Serial.println("Gagal load SD card.");
return;
}
Serial.println("OK.");
File textFile = SD.open("/WIFI.txt");
if (textFile) {
Serial.print("WIFI.txt: ");
while (textFile.available()) {
inputSTR=textFile.readString();
User = " ";
Password = " ";
Serial.println(inputSTR);
Serial.println(inputSTR.length());
Serial.println(inputSTR.indexOf(' '));
for (int i = 0; i < inputSTR.indexOf(' '); i++)
{
User.setCharAt(i,inputSTR.charAt(i));
//buf[i] = inputSTR.charAt(i);
// reportString.setCharAt(colonPosition, '=');
//Serial.println(User.charAt(i));
}
for (int i = inputSTR.indexOf(' '); i < inputSTR.length(); i++)
{
Password.setCharAt(i,inputSTR.charAt(i));
Serial.println(Password.charAt(i));
}
User.trim();
Password.trim();
Serial.println(User);
Serial.println(Password);
}
textFile.close();
} else {
Serial.println("error opening WIFI.txt!");
}
// ssid = "GalaxyM126A21";
//password="Salsa3349";
WiFi.mode(WIFI_STA);
//WiFi.begin(ssid, password);
WiFi.begin(User,Password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(".");
}
Serial.println("");
Serial.println("WiFi connected");
////Serial.printlnln("IP address: ");
////Serial.printlnln(WiFi.localIP());
}
void loop() {
//Serial.println("connecting to ");
////Serial.printlnln(host);
if (!client.connect(host, httpPort)) {
////Serial.printlnln("connection failed");
//return;
}
// We now create a URI for the request
url = "http://www.remotecal.com/index.php/cekperintah?idse=1&idst=2&idstk=3";
//Serial.println("Requesting URL: ");
////Serial.printlnln(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
////Serial.printlnln(">>> Client Timeout !");
client.stop();
return;
}
}
// while(client.available()){
// String line = client.readStringUntil('\r');
// //Serial.println(line);
int size;
int ang;
int ang2;
int ang3;
int jumlahsisa;
int jumlahsisa2;
int jumlahsisa3;
while ((size = client.available()) > 0) {
uint8_t* msg = (uint8_t*)malloc(size);
size = client.read(msg, size);
// Serial.write(msg, size);
azum = (char*)msg;
//////Serial.printlnln(azum.substring(213));
//azum = azum.substring(213);
ang = azum.lastIndexOf('Z');
azum = azum.substring(ang);
azum = azum.substring(0,2);
////Serial.printlnln(azum);
free(msg);
if(azum == "ZN"){
////Serial.printlnln("servo nyala");
for(angle = 10; angle < 90; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 90; angle > 10; angle--)
{
servo.write(angle);
delay(15);
}
}else if(azum == "ZM"){
////Serial.printlnln("servo dan stepper mati");
servo.write(10);
delayMicroseconds(100);
}else if(azum == "ZF"){
////Serial.printlnln("stepper maju");
//maju dan mundur
Serial.println("x-");
// digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
/*
for(int x = 0; x < 1000; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
*/
delay(200); // 200 ms delay
}else if(azum == "ZU"){
////Serial.printlnln("stepper mundur");
//maju dan mundur
Serial.println("x+");
// digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
/*
for(int x = 0; x < 1000; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
*/
delay(200); // One second delay
}else if(azum == "ZA"){
////Serial.printlnln("stepper kanan");
Serial.println("y-");
//kanan dan kiri
// digitalWrite(dirPink,LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
/*
for(int x = 0; x < 1000; x++) {
digitalWrite(stepPink,HIGH);
delayMicroseconds(500);
digitalWrite(stepPink,LOW);
delayMicroseconds(500);
}
*/
delay(200); // One second delay
}else if(azum == "ZI"){
////Serial.printlnln("stepper kiri");
Serial.println("y+");
//kanan dan kiri
// digitalWrite(dirPink,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
/*
for(int x = 0; x < 1000; x++) {
digitalWrite(stepPink,HIGH);
delayMicroseconds(500);
digitalWrite(stepPink,LOW);
delayMicroseconds(500);
}
*/
delay(200); // One second delay
}else{
////Serial.printlnln("servo dan stepper mati");
servo.write(10);
delayMicroseconds(100);
}
delay(50);
}
}
Buat RAB buat RISPRO 2024 dan sudah dikirim ke Adit
Komunikasi ESP NOW
ESPNOW adalah komunikasi nirkabel untuk chip ESP untuk lebih detail dapat dilihat dari CHIP
ini adalah pin out dari Weemos D1 mini clone
Di Arduino IDE pergunakan ESP32 WROOM perlu dipencet boot kalau ESP32 tidak perlu
Untuk ESP NOW bisa dipergunakann ESP32 sebagai sender dan ESP8266 reciever
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <esp_now.h>
#include <WiFi.h>
// REPLACE WITH YOUR RECEIVER MAC Address
uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x29, 0x1F, 0xB5};
// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
char a[10];
char b[10];
char c[10];
char d[10];
} struct_message;
// Create a struct_message called myData
struct_message myData;
esp_now_peer_info_t peerInfo;
// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void setup() {
// Init Serial Monitor
Serial.begin(115200);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_register_send_cb(OnDataSent);
// Register peer
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
}
void loop() {
// Set values to send
strcpy(myData.a, "pp 100");
strcpy(myData.b, "pread 10");
strcpy(myData.c, "loop 100");
strcpy(myData.d, "pp 200");
// Send message via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
delay(2000);
}
Untuk reciever ESP8266
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp-now-esp8266-nodemcu-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <ESP8266WiFi.h>
#include <espnow.h>
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
char a[10];
char b[10];
char c[10];
char d[10];
} struct_message;
// Create a struct_message called myData
struct_message myData;
// Callback function that will be executed when data is received
void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
memcpy(&myData, incomingData, sizeof(myData));
Serial.print("Bytes received: ");
Serial.println(len);
Serial.print("Char: ");
Serial.println(myData.a);
Serial.print("Int: ");
Serial.println(myData.b);
Serial.print("Float: ");
Serial.println(myData.c);
Serial.print("String: ");
Serial.println(myData.d);
Serial.println();
}
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != 0) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
}
Tidak ada komentar:
Posting Komentar