Arduino ADK Blink example not blinking sometimes - arduino

I have arduino uno connected with itead usbshield. I am receiving the data from android phone and it blinks only when i open serial monitor otherwise it is not. How to blink it independently. Is there any way it relates with opening serial monitor...?
I use pin 13 for blinking it...
Please guide me in to this...
This is the code..
void loop()
{
Usb.Task();
if(adk.isReady()) {
uint8_t msg[1];
uint16_t len = sizeof(msg);
uint8_t rcode = adk.RcvData(&len, msg);
if(rcode && rcode != hrNAK)
USBTRACE2("Data rcv. :", rcode);
if(len > 0) {
Serial.print(F("\r\nData Packet: "));
Serial.print(msg[0]);
digitalWrite(LED,msg[0] ? HIGH : LOW);
}
}
else
digitalWrite(LED, LOW);
}
Regards
Vinod

To which pin is the LED connected? My guess is that it is connected to pin 13
Pin 13 is also wired to the serial port. When ever there is any data transmission happening in the serial port, pin 13 is wired to blink.

Related

How to communicate with HM-19 BLE Module and scan using ultrasonic sensor

I am working on my senior project for school, and part of what I need to do is use an HM-19 Bluetooth 5.0 module to connect to another Bluetooth 5.0 module and establish a master slave connection.
I can do that just fine, but when I include the code needed for my ultrasonic sensor to do scan, my commands to my HM-19 don't return anything and I can't do any of the basic functions such as finding connections. I have tested it with and without the ultrasonic sensor code and the problem occurs when I use the sensor portion of the code.
TO BE CLEAR, all I am trying to do is just have my Bluetooth 5.0 chip connect to another and do normal commands while also inputting into my serial monitor a distance when I put my hand in front. THIS IS JUST A TEST, once I get that done I will move to what I really want to do.
IT'S JUST A STARTING POINT IN A PROJECT. I have a function call for my sensor and my bluetooth chip in the void loop, that's all that is in there.
I just want to know how to fix this issue. How can I scan with my ultrasonic sensor and send commands to my Bluetooth module? Any help would be greatly appreciated.
[Here are the results when the sensor is commented][1] and [here are the unsuccessful results that results in an infinite loop where I can't get to the portion of the code that returns what the chip says][2]. Lastly, although most of the links include stuff for the HM-10, the commands are basically the same for the HM-19. I'm adding more because stack overflow won't let me edit this post until there are more characters or something. I hope you have a good day/evening person reading this.
Here is my code:
// SerialIn_SerialOut_HM-10_01
//
// Uses hardware serial to talk to the host computer and AltSoftSerial for communication with the bluetooth module
//
// What ever is entered in the serial monitor is sent to the connected device
// Anything received from the connected device is copied to the serial monitor
// Does not send line endings to the HM-10
//
// Pins
// BT VCC to Arduino 5V out.
// BT GND to GND
// Arduino D8 (SS RX) - BT TX no need voltage divider
// Arduino D9 (SS TX) - BT RX through a voltage divider (5v to 3.3v)
//
#include <AltSoftSerial.h>
AltSoftSerial BTserial;
// https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
char c=' ';
boolean NL = true;
const int trigPin = 9;
const int echoPin = 10;
float duration, distance;
boolean wait_your_turn = false; //My attempt to make sure the sensor and the Bluetooth module don't interfere with each other
//if I'm sending data from the serial monitor to the bluetooth module and vice versa it switches to true and the bluetooth module
//does its thing, so the sensor doesn't get in the way.
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
Bluetooth();
Sensor();
}
void Sensor(){
if((wait_your_turn == true))
{}
else
{
Serial.println("Scanning for stuff.");
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
if(distance <= 20)
{
Serial.println(distance);
delay(500);
}
}
}
void Bluetooth()
{
if (Serial.available())
{
if(wait_your_turn == false)
Serial.println("Serial is available");
wait_your_turn = true;
while(Serial.available()>0)
c = Serial.read();
Serial.write(c);
if(c!=10&c!=13)
BTserial.print(c);
}
if (BTserial.available())
{
// Serial.print("We are at the bluetooth portion.");
while(BTserial.available())
c = BTserial.read();
Serial.print(c);
wait_your_turn = false;
}
}
[1]: https://i.stack.imgur.com/Dn4i0.png
[2]: https://i.stack.imgur.com/s9Ifv.png
Sorry, I forgot about this question. I figured it out. What I did was have 1 Arduino control the Ultrasonic sensor and send a character to the other Arduino when something was in range of the sensor. The other Arduino would then read the character and based on the character send it would perform an action. Thank you everyone who commented and have a great rest of your days.

RobotDyn Uno wifi not working

I am using a Uno+WiFi R3 ATmega328P+ESP8266 board, 32Mb flash, USB-TTL CH340G, Micro-USB.
I am able to see the network SSID on my PC and to connect to it, but when I tried to upload a sketch using the Arduino IDE I am getting espcomm_upload_mem failed.
I used the sketch from https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html
void setup() {
Serial.begin(115200);
pinMode(13,OUTPUT);
delay(500);
Serial.println("AT+CIPMUX=1");
delay(2000);
Serial.println("AT+CIPSERVER=1,5000");
delay(2000);
Serial.println("AT+CIPSTO=3600");
delay(2000);
}
void loop() {
while(Serial.available()) {
char Rdata;
Rdata=Serial.read();
if(Rdata=='A'|Rdata=='a') {
digitalWrite(13,HIGH);
delay(50);
} else if(Rdata=='B'|Rdata=='b') {
digitalWrite(13, LOW);
delay(10);
digitalWrite(13, HIGH);
delay(10);
digitalWrite(13,LOW);
} else {
digitalWrite(13, LOW);
}
}
}
Robotdyn Uno/Mega + WiFi boards have switches to make serial connections of Atmega to Usb, esp8266 to USB and Atmega to esp8266. To flash the esp8266 the switches 5, 6, 7 must be ON. switch 7 is flashing mode. to communicate with esp8266 from Serial Monitor, switches 5 and 6 must be ON.
For communication of Atmega with the esp8266 switches 1 and 2 must be ON. In tis settings none of the MCUs is connected to USB. Therefore it is better to use SoftwareSerial on some Atmega pins and connect them with jumpers to the esp8266 header. The header is documented in the schematic.
The code in post is for the Atmega directly connected to esp8266 (switches 1,2)

Using Arduino Serial to turn on LED. What is my error?

void setup(){
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
if (Serial.available() > 0){
int inChar = Serial.read();
if (inChar == 'H'){
digitalWrite(13, HIGH);
}
if (inChar == 'L'){
digitalWrite(13, LOW);
}
}
}
I have seen very similar programs. I don't get any compile errors, but the led light won't turn on. Is there an error in my code? Thanks
Sounds like a hardware issue. Double check that first.
Use a digital multimeter (DMM) to read the voltage between pin 13 and Arduino ground. It should output 5V when you send the 'H'. If it does, then your problem is the LED. If it does not output 5V when you send the 'H' then you have a software or serial communication issue.
Double check that you have the correct BAUD rate and COM port settings in whatever program is talking to the Arduino.

C code equivalent to serial monitor commands like Serial.begin,serial.flush,serial.read,serial.available,etc

Hi I am trying to learn coding microcontrollers on my own. I am trying to code my arduino board (ATMEGA8A-PU) in embedded C using the arduino ide itself. I have blinked my LED so far. Now I am trying to control its state using the serial monitor(sending "on" lights it up and "off" switches it off). But I don't know the C commands to do it.I successfully did it using the arduino Serial commands.
int led = 13; // Pin 13
void setup()
{
pinMode(led, OUTPUT); // Set pin 13 as digital out
// Start up serial connection
Serial.begin(9600); // baud rate
Serial.flush();
}
void loop()
{
String input = "";
// Read any serial input
while (Serial.available() > 0)
{
input += (char) Serial.read(); // Read in one char at a time
delay(5); // Delay for 5 ms so the next char has time to be received
}
if (input == "on")
{
digitalWrite(led, HIGH); // on
}
else if (input == "off")
{
digitalWrite(led, LOW); // off
}
}
So please help.
You are using Serial class and functions like begin(), print() etc from the Serial class which is C++ language. These are the C++ commands native to the Arduino development environment. So anyway you ar using C/C++ commands here.

BLUNO Distance Monitoring Project

I'm trying to do a project where BLUNO (Arduino UNO + BLE) will connect to an iBeacon and make use of the RSSI detected.
I've already made contact between the BLUNO and the iBeacon through the AT commands. I can get RSSI result in the Arduino IDE serial monitor when I ping it with AT commands.
My problem now is in sending those AT commands through an Arduino sketch. I know I've to use Serial Communication, but my Serial.Available function never returns more than 0.
void setup() {
pinMode(13, OUTPUT);
Serial.begin(115200);
Serial.print("+++\r\n");
Serial.print("AT+RSSI=?\r\n");
}
void loop(){
if(Serial.available()){
digitalWrite(13, HIGH);
delay(5000);
}
}
What is irritating me is that I can connect BLUNO to my iPhone and get the RSSI on the serial monitor through AT commands. But that above code doesn't work!
Any help?
I'm almost done with the whole project for now.
my mistake in the last code was the initiation part that has to be done before the AT commands. The right way is
Serial.begin(115200); //Initiate the Serial comm
Serial.print("+");
Serial.print("+");
Serial.print("+"); // Enter the AT mode
delay(500); // Slow down and wait for connection establishment
instead of
Serial.print("+++\r\n");
so yeah the rest is kind of alright. Keep in mind that this BLE thing REALLY sucks in terms of accuracy in locating a beacon. The RSSI reading keep fluctuating and the calculated distance using the simplified equation here somewhere on Stack overflow is REALLY unreliable.
So yeah keep that in mind yo!
Here's my full code just for reference.
// while the AT connection is active, the serial port between the pc and the arduino is occuipied.
// You can manipluate the data on arduino, but to display on the serial monitor you need to exit the AT mode
char Data[100];
char RAW[3];
int INDEX;
char Value = '-';
void setup() {
pinMode(13, OUTPUT); // This the onboard LED
pinMode(8, OUTPUT); // This is connected to the buzzer
Serial.begin(115200); //Initiate the Serial comm
Serial.print("+");
Serial.print("+");
Serial.print("+"); // Enter the AT mode
delay(500); // Slow down and wait for connectin establishment
}
void loop(){
Serial.println("AT+RSSI=?"); // Ask about the RSSI
for(int x=0 ; Serial.available() > 0 ; x++ ){ // get the Enter AT mode words
//delay(20); // Slow down for accuracy
Data[x] = Serial.read(); // Read and store Data Byte by Byte
if (Data[x] == Value ) // Look for the elemnt of the array that have "-" that's the start of the RSSI value
{
INDEX=x;
}
}
//Serial.println("AT+EXIT");
RAW[0] = Data[INDEX]; // Copy the RSSI value to RAW Char array
RAW[1] = Data[INDEX+1];
RAW[2] = Data[INDEX+2];
RAW[3] = Data[INDEX+3];
int RSSI = atoi(RAW); //Convert the Array to an integer
//Serial.println(RSSI);
//delay(200); // Give the program time to process. Serial Comm sucks
double D = exp(((RSSI+60)/-10)); //Calculate the distance but this is VERY inaccurate
//Serial.println(D);
if (D>1.00) // If the device gets far, excute the following>>
{
digitalWrite(13, HIGH);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(13, LOW);
digitalWrite(8, LOW);
delay(500);
}
}

Resources