Arduino RF Receiver picking up some 433MHz signals but not others - arduino

I have an Arduino and a 433MHz receiver running the code below, using the RCSwitch Library. The code is working fine when I use a remote like the "BN-LINK ES1513-5-2 Wireless Remote". The bits/signal prints to the window and everyone is happy.
But when I try to pick up the signal from a dog collar(No-Shock) remote 433HMz, I get nothing.
Both remotes say they are transmitting at 433MHz.
I have multiple "BN-LINK ES1513-5-2 Wireless Remote" and I can see signal from these remotes. If i hook up another Arduino with a RF transmitter i can pick up the signal.
Any ideas why I can see signals from some but not the other?
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}

Transmitting at 433 Mhz is only one part of the infrastructure, the other issue is at what protocol the transmission is done and that would probably be different from a remote control to a dog collar.
In the ReadMe section of the rc-switch library you can find a list of supported chipsets. EV1527 for example is one of the common and can be found on many the low-cost 433Mhz devices including remote controls. You could look for information about that, however, to my opinion, if you are to use a device/chipset/protocol supported by this lib, you should no longer worry about low-level communication.

Related

Arduino with SIM 900a- How can I store all incoming messages into a text file?

I have connected my Arduino Uno with SIM 900a GSM module. I want to store all my text messages that I receive on the SIM inside the GSM module to a text file continuously.
I can send SMS through the code shown below but I cannot receive and save my messages to a file. What is the correct way to do this?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
void setup() {
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
void loop() {
if (Serial.available()>0)
switch(Serial.read()) {
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage() {
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+9779813546162\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage() {
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}
The Arduino cannot naturally create files on your host system, so you will need to
run an independent program on the host system which watches the serial connection and logs the messages produced by the Arduino (my recommendation)
attach some storage to the Arduino (such as an SD card shield)
have the Arduino pretend to be a keyboard and output as if it were being typed upon
Independent Program
This is the route I would recommend
easy to use and test (just check your file has the contents you want)
will not "mess up" your Arduino
can do other work and tests on system
do not need to deal with storage problems
This simple Python script may work for your needs: Serial data logging with python
This post suggests you can do it with a 1-liner under both Linux (may be the same for Mac) and Windows, but you may run into trouble with the Serial Port's baud rate. If this answer is dated or only gets some of the output (ie. a single line and then exits), you could run it in a loop or search further. You'll need to pick the right serial port as there may be a few (or just one with a different name).
Attached Storage
Many vendors will sell you a Shield for this
Adafruit Assembled Data Logging shield for Arduino (deals with filesystem automatically, nice)
SparkFun microSD Shield
generally searching "Arduino SD Card Shield" (will probably turn up cheaper versions, but they may not be of good quality, have nice drivers, tutorials, etc.)
Beware that Flash Storage can be annoying to deal with
need to eject (perhaps swap out) the card and look at it periodically to both see the results and if the results are correct
filesystems hoopla (should I use FAT, exFAT, ext2..)
ensuring the Arduino can write the filesystem (though modern shields probably do this for you, at least the Adafruit one suggested above does)
Keyboard Emulation
To start, I do not recommend doing this for the following reasons, though it's pretty neat and doesn't require any more hardware than you have.
BEWARE may make your Arduino unusable without some start gate such as waiting for a switch to be enabled (haywire inputs to computer: cannot program it)
requires total access to the computer while running (computer cannot be otherwise used)
not easier to configure than an independent logger (annoying trial and error / waiting / haywire inputs)
Official docs: https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
They have the same warning I would give
A word of caution on using the Mouse and Keyboard libraries: if the Mouse or Keyboard library is constantly running, it will be difficult to program your board. Functions such as Mouse.move() and Keyboard.print() will move your cursor or send keystrokes to a connected computer and should only be called when you are ready to handle them. It is recommended to use a control system to turn this functionality on, like a physical switch or only responding to specific input you can control. Refer to the Mouse and Keyboard examples for some ways to handle this.

Make sounds from photoresistor on arduino using MIDI on garageband?

I'm having trouble trying to make sounds from my photoresistor using MIDI. I have a MIDISPORT USB. I connected MIDI OUT from my breadboard from the MIDI JACK and my MIDI IN isn't connected to anything because I don't know where it should go or if I should just leave it. I'm using Hairless MIDI serial program to connect my arduino with MIDI, they seem to receiving signal from my usb on the arduino side and the Midi side but I don't hear any sounds.
How does garageband come in to this? It doesn't have to be garageband, i just want to make this work and hear the sounds. I made sure garageband is connected to MIDI as well as having HairlessMIDI at serial 9600 and my arduino at serial.begin at 9600. everything seems to look good so far. I just don't know why I don't hear anything. Am I supposed to hear it from garageband, if so how?
here's my arduino code,
byte noteON = 144;//note on command
void setup() {
Serial.begin(9600);
}
void loop() {
MIDImessage(noteON, 60, 100);//turn note on
delay(300);//hold note for 300ms
MIDImessage(noteON, 60, 0);//turn note off (note on with velocity 0)
delay(200);//wait 200ms until triggering next note
}
//send MIDI message
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}
If I understood your setup correctly, you use:
an arduino with a sensor to generate a signal, this is the instrument
MIDISPORT USB http://www.performanceaudio.com/media/pdf/121/3757_m.pdf to make the link between the instrument and the computer
HairlessMIDI which converts a serial text protocol to midi. http://projectgus.github.io/hairless-midiserial/#getting_started
I am unsure you need the MIDISPORT at all. HairlessMIDI already makes the link between an Arduino program and a MIDI expander application (see tutorial in the link above).
According to this page, the Arduino must use the MIDI Library, and the init code looks like this.
void setup() {
MIDI.begin();
Serial.begin(115200);
}
Note the 115200 baud rate. The serial port on Arduinos must use a specific baudrate, otherwise the host and slave won't be able to talk to each other.
I think you must connect your setup to the MIDI In side on the HairlessMIDI application. If GarageBand is running, you must be able to select it in the drop down list.

SoftwareSerial example not working as expected

I recently bought an Arduino UNO to read the data outputted by my Smart Meter. The meter uses serial communication and I would like to see the values being outputted on my laptop screen. I figured I would need to use the SoftwareSerial library to read the incoming data and print that data on my screen using the hardware serial and the Serial Monitor in the Arduino IDE. To become familiar with (software) serial communication on the Arduino, I reviewed the documentation of the SoftwareSerial library. Problem is, I can't get the most basic example to work and I have been stuck on this for quite a while now. The example code is below, the example can be found here
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
As far as I understand this, the following should happen:
- Type text in Serial Monitor window.
- Serial.read() reads this data and writes it to the Software Serial.
- The Software Serial reads this data and writes it back to Serial.
- That which was written appears on the screen.
But whatever I try, nothing happens. Among things I tried to following:
- Change the baud rate for both software and hardware serial (9600 for instance).
- Tried a different SoftwareSerial library (AltSoftSerial).
- Tried different RX and TX pins for SoftwareSerial.
- Instead of Serial.write(mySerial.read());, store the result in a char first.
I'm probably missing something obvious. I would be grateful to anyone who could shed some light on this or offer an alternative way for me to read the data from my Smart Meter.
Edit
I had no wiring, because the example specified "There is no circuit for this example". I tried all three options suggested by #slash-dev, but none had the expected behaviour:
SoftwareSerial with wires connecting pin 1 to pin 10 and pin 0 to pin 11. It prints strange characters:
Goodnight moon!
Ùniÿhtÿmoÿn!ÿ
nihtmoÿttt
AltSoftSerial with wires connecting 1-8 and 0-9. First prints Goodnight moon! and then it keeps printing Ô당¥�¡Ñ�moon!.
NeoSWSerial with wires connecting 1-10 and 0-11. Same as AltSoftSerial but keeps printing Ôë‹–+ë¡Ñ�j½½¹…j.
The baud rates must be the same on Serial and mySerial.
And you don't describe the connections, so I have to ask: Did you connect a wire from pin 1 (Serial transmit) to pin 10 (mySerial receive), and another wire from pin 0 (Serial receive) to pin 11 (mySerial transmit)? Note how they are crossed.
AltSoftSerial is really the best choice, but it only works on pin 8 (RX) and pin 9 (TX), which would require connecting 8 to 1 and 9 to 0. SoftwareSerial is very inefficient, because it disables interrupts for long periods of time. This can interfere with other parts of your sketch or other libraries.
My NeoSWSerial library is another alternative. It's almost as efficient as AltSoftSerial, but it works on any two pins. It can transmit and receive at the same time (unlike SoftwareSerial), but it only works at bauds 9600, 19200 and 38400.
EDIT:
I think what you've tried is probably working ok. All the software serial libraries use interrupts for processing individual bits instead of one interrupt per character. When there are other interrupts in the system (millis() TIMER0 or Serial), the bit "calculations" can be affected. This manifests as receiving the wrong byte. Your loopback test makes it especially susceptible because the sending and receiving are synchronized (the initial receive interrupt occurs while the transmit interrupt is starting the next char).
If you just hook 0 to 1, I think it will work, because the UART is able to send and receive at the same time, and it deals with complete characters, not bits. The character interrupts do not disturb the sending or receiving of the bits.
In developing the NeoSWSerial library, I have seen this manifest the same way. I had to use two Arduinos to fully test asynchronously (i.e., not synchronized). In your case, using AltSoftSerial for the SmartMeter should work fine, and you can choose different baud rates. If you are echoing the SmartMeter characters to Serial, be sure you have a higher baud rate on Serial.
This is most likely not related to the issues now 5 years ago, but in my case I was using the Arduino IDE 2.0.0-rc5 which was not writing to the soft serial for unknown reasons. I downgraded to Arduino IDE 1.8.19 and the same serial sketch worked.

Handling serial input on Arduino with interrupts on a specific character

I'm working on an educational robotics project that should allow control of the robot over Bluetooth. The robot is an off-the-shelf robot with a serial interface that the Arduino is driving normally autonomously.
I'm trying to allow users to write a series of commands to the Bluetooth serial port (connected to hardware serial pins or software serial pins) while the automation is still running and when they send a new-line, the series of commands is sent to other parts of the robot.
I've used other microcontrollers and written a simple interrupt routine when a pin is pulled high or low, but I am not sure how to handle an interrupt on a character. I think that an interrupt is the best way to do this, but I haven't had much experience with Arduino, so there many be functionality I'm not aware off.
TL;DR: If I want the Arduino to execute code when a certain character arrives on a serial port, should I use an interrupt method?
I also want to add, as this is an educational project, I would like to stay fully on Arduino, several friends and colleagues have recommended alternate chips or MCUs that would have the functionality but I want to stay friendly to new programmers and engineers.
The built-in HardwareSerial does not have support for interrupt-driven handling of characters. Many sketches are OK with the typical polling approach:
while (Serial.available()) {
char c = Serial.read();
// Code that watches for certain characters
.
.
.
}
There's nothing about what you describe that requires interrupts, but you could use an extended version of HardwareSerial that I wrote (modified), called NeoHWSerial. It calls a function that you provide from the interrupt service routine (see documentation).

Serial.begin(speed, config) not compiling for Leonardo Board

I would like to configure my serial communication to have no parity, 1 start- and 2 stop-bits. The documentation for Serial.begin(speed, config) states:
(...) An optional second argument configures the data, parity, and stop bits. The default is 8 data bits, no parity, one stop bit.
The documentation also lists the possible configuration-values. According to my (limited) understanding, I need SERIAL_7N2 or SERIAL_8N2 to meet my requirements. (I'm not sure how the data-bits relate to the the 1-start-bit that I need.)
However, I can't even compile because I have no idea how to supply that configuration value to the begin method. (I don't have much Arduino/C++ experience).
In my code, I've tried the following two variants:
Serial.begin(9600, SERIAL_8N2);
Serial.begin(9600, "SERIAL_8N2");
Am I missing something?
Additional information:
Serial.begin(speed, config) has been introduced with the latest Arduino 1.0.2 IDE version.
The code defining/implementing the begin methods can be found:
HardwareSerial.h
HardwareSerial.cpp
Edit:
According to the replies from PeterJ and borges, the following variant is correct.
Serial.begin(9600, SERIAL_8N2);
However, it's still not working.
I found that the compile error doesn't occur if I change the configured board from my Arduino Leonardo to Arduino Uno.
Therefore, it could be a bug occurring only with a subset of boards ... or maybe it's not supported?!
Edit 2:
It's now solved :) The answer of borges pointed me to the right solution!
You mentioned in a comment: (edit: and now is in the title)
I don't get the compile error if I change the board from my "Arduino Leonardo" to "Arduino Uno".
The Arduino Leonardo has some peculiarities regarding serial communication:
Leonardo has a microcontroller (ATmega32U4) that has native USB communication. To maintain compatibility as the entire ecosystem already established, the Leonardo virtualizes a serial communication over USB. You have access to this communication using Serial in the code. Physically you have access to that communication via the USB plug.
To use the "real" serial communication (AKA serial TTL), you need to use pins 0 (RX) and 1 (TX). In the code you would use Serial1 (notice the number 1!).
An example:
void setup() {
Serial1.begin(9600, SERIAL_8N2);
Serial1.println("Hello?");
}
void loop() {
}
For more information (recommended):
Arduino Leonardo
Guide to the Arduino Leonardo
The first method should be OK, so you have a compiler configuration or include problem. Make sure you have the following include at the top of your file:
#include <HardwareSerial.h>
Also while SERIAL_8N2 is valid it's an odd setting rarely used. You'll most likely want SERIAL_8N1.

Resources