Arduino communication in wireless IR system - arduino

I have two Arduinos that I want to put in a wireless system to relay an IR code from a hand held remote in one room of the house, to a settop box located in another room. One Arduino has an IR decoder which decodes the key from a hand held remote, and sends it to the other Arduino parked in front of the box with an IR emitter. The system, in parts, works fine. When I get the code from the detector (to my PC) and send it manually (from my PC) to the emitting Arduino, it controls the box properly. But when I try to send the code wirelessly directly between the Arduinos, it doesn't work quite right. The commands do not appear to be relayed correctly and the emitting Arduino can't control the bx.
Here is what the decoding Arduino code looks like. "myNumber" holds the 4 byte key:
myNumber.UL = results->value;
Serial.write(&myNumber.B,4);
When the decoder detects the IR pattern, it posts the following to the Serial port whether I use the emitter or depress the on/off key on the remote. The key in question is 61A0F00F (power on/off):
Hex Field ASCII
0000 0F F0 A0 61 ...a
The decoder puts out this same response when I direct the actual remote towards the detector, or when I am driving my emitter with the code 61A0F00F. So it can't tell the difference between the actual remote and the Arduino-driven emitter. The problem is that this output is not understood correctly by the Arduino on the emitting end of the system.
Here is what the emitting code looks like:
void loop() {
int x = 0;
while (x < 4) {
if (Serial.available()) myNumber.B[x++] = Serial.read();
}
Serial.print(myNumber.UL, HEX);
if (x==3) irsend.sendNEC(myNumber.UL, 32); //drive IR emitter with NEC code
delay(10000);
And the serial output looks like this:
HEX field ASCII Field
0000 36 31 41 30 46 30 30 46 61A0F00F
When I put this hex code in manually, i.e. via CoolTerm, inverted (so 0FF0A061) the settop box responds (by turning on). When I link the Arduinos wirelessly, it does not.
Can anyone see what is wrong with the communication above? The numbers in the hex fields don't look quite right, the hex field from the decoder does look like hex, but the hex field from the emitter looks like ASCII? So is the emitter expecting an ASCII number but getting hex instead? I would have thought that the Serial.read and Serial. write would work the same way.
This is highly frustrating, as it appears that the system almost, almost works, BUT NOT QUITE!!
Any help/insight would be appreciated.

First a disclaimer: I haven't coded my arduino for several years.
At first glance it would appear you are being bitten by a conversion bug. I see a lot of conversions from byte to long etc. The key here would be to break things down to their simplest level and verify each level works.
First off I would verify the number of bytes being sent by checking the return value from Serial.write is indeed 4. Something as simple as flashing an led if Serial.write returns 4.
On the receiving end I think I would use ReadBytesUntil as this seems to be designed to do what you want and builds in some error checking (time outs and only 4 bytes).
I hope this helps. If not follow the golden rule: when in doubt - post more code!

Hope the late response helps.
The output data from the emitting end is correct. In your case, myNumber.UL = 0x61A0F00F. When executing the code "Serial.print(myNumber.UL, HEX);", the print class actually sent out the char sequence as '6''1''A''0''F''0''0''F'. So in your serial monitor the ACII data is "61A0F00F", and the corresponding HEX data is "36 31 41 30 46 30 30 46". You are confused about transferring data via text and binary format.
The problem of your code is at line "if (x==3) irsend.sendNEC(myNumber.UL, 32);". After receiving the four bytes data, the x is 4 other than 3. Changing the condition x==3 to be x==4 can fix your issue.

Related

Decode RFID tag Hexadecimal values to Decimal Serial Number

I have around 10k+ devices, each with both a visible serial number printed on a label and a RFID tag from which the serial number can be read as well. My problem is that when I read a RFID tag I get a bunch of hexadecimal values and I am unable to retrieve the actual serial number value from them as it is not a straightforward decimal to hex encoding.
Here are a couple of information that I get when scanning the RFID tag with the Android App "NFC Tools":
- Tag Type: ISO 15693 NXP - ICODE SLIX
- Technology available: NfcV, Ndef
- Serial number: 3C:FB:88:14:50:01:04:E0
- DSFID: 0x00
- Data format: Unknown
- Size: 38 / 106 Bytes
- Writable: Yes
- Can be made Read-only: No
I have noticed that each and every RFID tag contains the same 'header' 50:01:04:E0, so it means there should exist a way to retrieve my serial number from 3C:FB:88:14. In this particular instance, the serial number is 11926214.
I have scanned about 30 units manually, but I would like to avoid having to scan all 10,000 as it is error prone to write down the hex values and the corresponding serial. Is it possible at all with the above information to figure it out ?
Section 9.2.1 of the datasheet for the chip might help
https://www.nxp.com/docs/en/data-sheet/SL2S2002_SL2S2102.pdf
Some App's might show the most significant bit first as it seems with this app (i.e. in reverse to the more normal orientation)
That actually puts 3C:FB:88:14:50 as the IC manufacturer serial number
or 50:14:88:FB:3C as the manufacturer defines it.
I've tried various Hex to Decimal converts like https://www.rapidtables.com/convert/number/hex-to-decimal.html and cannot get any combination and significant bit orientation to convert to the make the device serial number.
These chips also have user defined memory that App's has not been read and the Device Serial could be stored in here and not related to the Tag's serial number. (As the RFID serial is programmed by NXP at manufacture time it is unlikely to also be the devices serial number)
I suggest actually using the App TagInfo by NXP as this is by the Manufacturers of the Chip and can show you the all the raw memory blocks (It can on the card type I use)
BUT it seems that NXP have removed the TagInfo App very recently :-(
Update: Seems you might be able to side load the APK from https://apkpure.com/nfc-taginfo-by-nxp/com.nxp.taginfolite (with the associated risks)
Of course you can use the linked datasheet to write your own App to read the user memory area where the Device Serial might be stored.

GPS data with Arduino

I am using CRIUS Neo-6 GPS module and I would like to send data from GPS via GSM module every 10 seconds. The piece of code I have looks like this:
if (Serial1.available() > 0)
if (gps.encode(Serial1.read()))
{
double hour = gps.time.hour();
double minute = gps.time.minute();
double second = gps.time.second();
Serial.println("Sending SMS:");
GPRS.print("AT+CMGF=1\r");
delay(100);
GPRS.println("AT+CMGS= \"00*********\"");
delay(100);
GPRS.print("HOUR=");
GPRS.print(hour);
GPRS.print(" MINUTE=");
GPRS.println(minute);
GPRS.print(" SECOND=");
GPRS.println(second);
delay(100);
GPRS.print((char)26);
delay(100);
GPRS.println();
Serial.println("Text sent.");
Serial.println();
delay(10000);
}
Serial1 is a SoftwareSerial instance for communication with GPS module.
Now this sends an SMS every 10 seconds but the data is messed up, it is like the time doesnt refresh always. I get something like:
HOUR=6.00 MINUTE=37.00 SECOND=54.00
HOUR=6.00 MINUTE=37.00 SECOND=54.00
HOUR=6.00 MINUTE=37.00 SECOND=54.00
HOUR=6.00 MINUTE=38.00 SECOND=15.00
and so on.. Its like always two or three identical SMS-es and then next one with 30 seconds gap. What should I change to always send latest gps time?
1) Tell us what Arduino you are using. It looks like it might be a Mega.
2) Post your entire sketch and identify what libraries you are using. It looks like it might be TinyGPS++.
5) Don't use double. It's the same as float on the Arduino. But don't use float either. Just use int or unsigned char.
Now then. Did the example programs work? That would confirm that you have good satellite reception.
Next, did you know that your GPS sends several different kinds of messages each second? Not all messages contain a time field (see this table of messages vs. fields).
And finally, these lines will cause a lot of trouble:
delay(100);
...
delay(100);
...
delay(100);
...
delay(100);
...
delay(10000);[/code]
While the sketch is stopped at these delays, no GPS characters are being processed. But then you wait for just one message to get parsed with "if (gps.encode", and you send another SMS. The only message that got parsed probably did not have a time field, so you send the same time.
You should research ways to avoid using delay. Take a look at some posts on the Arduino forum, "Serial Input Basics" and "How to do several things at a time" in Useful Links.
Also, I wrote a better GPS library, called NeoGPS. It is much smaller and faster than TinyGPS++. The examples are structured better, too. NMEAtimezone.ino is closest to what you are doing. If you'd like to try it, be sure to follow the Installation instructions. You should try several programs as described, in this order: NMEA, NMEAdiagnostic and NMEAorder if necessary, and NMEAfused. Then try NMEAtimezone, and modify it for what you are doing.

I2C communication between pic32 and MPL3115A2 Altitude/Pressure Sensor

I'm trying to do something really simple and I'm having a bit of trouble getting it to work. I'm working with the MPL3115A2 Altitude/Pressure Sensor and a pic32 uC32 board, and I'm trying to communicate between the two using I2C. (uC32 board is similar enough to arduino that it's practically the same in terms of coding).
I'm using the wire library and I'm simply trying to read register 0x0C from the MPL3115A2, which should give me the device ID.
Here's a code snippet (the define is at the top of the code and the rest is in the main loop):
#define barAddress 0x60
Wire.beginTransmission(barAddress);
Wire.send(0x0C);
Wire.endTransmission();
Wire.requestFrom(barAddress, 1);
uint8_t a = Wire.receive();
Serial.println(a, HEX);
So I start the transmission with address 0x60 (From the datasheet: The standard 7-bit I2C slave address is 0x60 or 1100000. 8-bit read is 0xC1, 8-bit write is 0xC0.). Then I send 0x0C because that's the register I want to access. I then end transmission, and request 1 byte from address 0x60, receive that bit into a 8-bit variable, then print it.
The problem I run into is that when I print it, I just get 0. I don't get the device ID, just 0. No matter what register I try to read, I get 0.
I've been banging my head against a wall for the past few days trying to get this to work. I've attached something I've captured with a logic analyzer, as well as a list of registers from the datasheet of the MPL3115A2 that I've been trying to access.
Using a logic analyzer I can see the clock and data lines. The clock seems normal and the data line gives me the following:
START
Write['192'] + ACK
'12' + ACK
STOP
START
Read['193'] + ACK
'0' + NAK
STOP
This all seems correct to me (192 and 193 come from 8-bit write and read being 0xC0 and 0xC1), except for the '0'. I should be getting the device ID, not 0.
Thanks for any help with this!
You should look at Freescale's app note AN4481, which is referred to by the datasheet. Page 5 shows the single-byte read operation which is what you are doing, except that the register address write must not be followed by a STOP but instead uses a REPEATED-START.
I'm not familiar with the Wire library but it look like all you need to do is remove the Wire.endTransmission(); between the send and requestFrom.
Hopefully, this will solve your problem.

Re-entrant code?

I am using the Wire library to move some data from a shield to the Arduino.
The shield always puts out exactly 36 bytes (GPS device), but the Arduino sees two data transfers that together add up to 36 bytes. Not always the same count in each of the transfers, but always 36 bytes total. The setup() routine is re-run every time the data comes in.
It's as if the library is re-entering the Arduino application and screwing it royally.
Is this possible?
If setUp() is being run every time data comes in (and are you sure about this?) then this means that the Arduino is resetting/restarting for some reason. How are you powering the GPS shield? If it is glitching the power to the Arduino (drawing too much current perhaps) then that could cause a reset. It could also be something with your code using up too much memory. I'd look at the power issue first.
If you are using Wire.available, note that it does not guarantee that it will return the number of bytes sent. You will need to call it repeatedly until it returns zero.
See an example in the Arduino documentation.

An issue with uart and pic 18f452

i have a problem with pic18f452 and uart
i use simplest code like that:
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
and between forever while loop i have this code
UART1_Write_Text("HELLO2");
Delay_ms(1000);
also i have in my hardware lcd module it works very fine but my received data on pc
is a scrap like that
???m
i have checked all connection sothand time nothing wrong also i have changed MAX232 ic but with no luck ?!
my hardware is like that
finall all my connections are ok (polarity and every thing else ?)
EDIT : i use mikroc as a compiler
Looks like a baud rate error. Have you checked that your oscillator settings are resulting in the expected frequency? Does the serial library you are using expect a certain clock frequency and you are sure that you are running at that frequency, or does it work over a set of frequencies and you have correctly informed the serial library what frequency you are using? Also it would be useful to see the byte received as a decimal or hex number rather than just ASCII.
What about the start bits, number of data bits, parity, and stop bits? Are they the same on both ends?
It happens when you have loose connections i.e. from max 232 to Pic & from max 232 to PC.
Try checking the fluctuations over the transmit pin or usr Oscilloscope to see the ASCII values of Hello World alphabets.

Resources