[SOLVED] Sending 25 bits at 1200bps

Hey,

I just got an assignment to investigate what signal a dog collar was sending. I used an SDR to get the signal and I decoded the 7 buttons and got this:

1)   [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,0,0,0]
2)   [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,1,0,0,0,0]
3)   [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,1,1,0,0,0]
4)   [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,0,1,0]
5)   [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,1,0,0]
6)   [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,1,1,0]
7?)  [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0]

If you notice, there are 25 bits being sent in the time period of about 0.02 seconds. (I'll just assume the bps is a generic 1200).

Now my job is to make an Arduino transmit this signal, so that the receiver gets the same thing. I'm kind of lost here... I have a 315MHz module that is needed, and I have experience using VirtualWire with it, but not really sending raw binary over.
Does anyone know how to send 25 bits using 1200bps? 25 bits is a really abnormal thing... but that's what it is. So far by Googling some solutions I have only found solutions for sending bytes (8 bits) and nothing about 3 bytes and 1 bit :stuck_out_tongue:

Attached is a .wav baseband recording of button (1) being pressed. If it's not possible to send 25 bits, is there a way that I can just play this .wav file into the DATA port of the transmitter?

Thanks in advance!

1.wav (200 KB)

Did you open the collar or the receiver to see what chips are inside ?

The decoded '1' and '0' differ only with 4 bits. That is half a byte.
You could use VirtualWire or RadioHead to transmit a byte, or you could sent 25 bits. You can transmit 4 bytes (4 bytes = 32 bits).

The major problem is how to create a signal that is recogned by the receiver. It would be helpful if the protocol was known.
When the dog collar is cheap, it is probably with 2262/2272 chips.

Did you open the collar or the receiver to see what chips are inside ?

The chip on the transmitter is SCL2240P AECLN6. I tried looking it up and I got nothing...

You could use VirtualWire or RadioHead to transmit a byte, or you could sent 25 bits. You can transmit 4 bytes (4 bytes = 32 bits).

You can do that with VirtualWIre to just send bits??
I considered the 32 bit method by adding 7 "0"s. Turns out that the hex is still the same... When I put the 25 bits (button 1) into a converter I got 0x7FAD28. It seems like it ignored the first 0 in the binary and just gave me a 24 bit number.
I then tried this code:

void setup()
{
 Serial.begin(1200);
}

void loop()
{
	Serial.write(0x7F);
	Serial.write(0xAD);
	Serial.write(0x28);
        delay(200);
}

Then I looked at it on the SDR. I connected DATA to pin1 (TX). I got a really weak and noisy signal, but I'm not sure if it's correct. (I will expand on soon)

The major problem is how to create a signal that is recogned by the receiver. It would be helpful if the protocol was known.
When the dog collar is cheap, it is probably with 2262/2272 chips.

I actually do not have the collar with me. I asked to receive it so I can test if it actually works. For now, all I am doing to verify success is using the SDR to compare the waves generated.

So that brings me back to the 24 vs 25 bit issue when I got a signal on the SDR...

is sending [0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,0,0,0]
The same as sending [0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,0,0,0] ?

Do I need an amplifier on the Arduino TX pin? The dog collar runs at 9v and has a solid signal: should I power the RF module on 9v and use a transistor on the DATA pin?

Thanks so much for your help; I'm getting somewhere I feel.

If the transmitter is such a very small module with a round metal thing (with SAW oscillator inside), you can power it with 9V and still use the Arduino 5V pin to switch it on and off. But if it is something else, I don't know.
For testing, keep everthing at 5V. Did you connect a wire to the antenna pin ?

I can find references for PT2240 and PT2262. Perhaps you are in luck and it is a PT2240 and they have the same protocol.
You could try the RCswitch library. You will need the transmitter and let the RCswitch try to make something out of it.
The advanced example can determine the timing and the protocol.

The VirtualWire can transmit a few bytes. How set the bits in a few bytes is 'C'-programming. You can do that with a struct or in a loop.
However, if the RCswitch library detects it, that library will show the codes to transmit.

Did you use the SDR software that is capable to record the signal ? Because your recording 1.wav is confusing for me.
Perhaps you did record the 315MHz signal, instead of the AM demodulated signal.
Have a look at these projects, and take a look at the screendump of Audacity:
http://www.timberline.se/blog/?p=210

If the transmitter is such a very small module with a round metal thing (with SAW oscillator inside), you can power it with 9V and still use the Arduino 5V pin to switch it on and off. But if it is something else, I don't know.
For testing, keep everthing at 5V. Did you connect a wire to the antenna pin ?

It is a SAW oscillator (the common RF module), so I will connect Vcc of the transmitter to 9v and the DATA to just the TC pin. I have a 6.8 in antenna connected to it (right now I am testing it on a 433MHz transmitter because a 315MHz one is not yet available)

I can find references for PT2240 and PT2262. Perhaps you are in luck and it is a PT2240 and they have the same protocol.
You could try the RCswitch library. You will need the transmitter and let the RCswitch try to make something out of it.
The advanced example can determine the timing and the protocol.
GitHub - sui77/rc-switch: Arduino lib to operate 433/315Mhz devices like power outlet sockets.

Hey it actually might be a PT2240! Thanks! I usually can recognize varying chip names but I never played with this before.
I'm looking at the RCswitch library. I'll take a look at the ReceiveDemo_Advanced. I will get back on that.

Did you use the SDR software that is capable to record the signal ? Because your recording 1.wav is confusing for me.
Perhaps you did record the 315MHz signal, instead of the AM demodulated signal.
Have a look at these projects, and take a look at the screendump of Audacity:
Parked at Loopia
Controlling 433Mhz RF power sockets with a RFM12B module – Martin's corner on the web
Captain Bodgit: Hacking 433MHz Remote Controllers

I was using SDR# on a NooElec antenna. I don't know why but this is a problem I get. When I record the Audio I get unintelligible and weak signals. I hear the clearly, however. That .wav file was indeed the baseband recording, not the audio. I found it easier to decode than the audio: when I compared it to the audio I could see similarities, so I decided to just record the baseband. If you look at it, the thinner chunks are 0s and the thick ones are 1s.
Sorry for the confusion... The whole day yesterday was spent trying to get a nice audio recording, and I gave up and settled with the baseband, which got me decent results.

About RCSwitch...

So I'm looking at it now. I will need to wait for my 315MHz receiver to arrive on Monday...
I'm assuming all I have to do is upload this onto an Arduino Mega and connect DATA to pin 2? (Interrupt 0 is pin 2 for 2560 I think...)

When I press a button it will then send the timing and protocol to the serial port, and I can manipulate it from there (Assuming the dog collar is just a PT2240)?

I will update the progress once the modules arrive. For now I have to wait for the darn USPS ground shipping.

Again, Thank you so much for your help!

I used http://www.hdsdr.de/ for recording the AM-demodulated signal. The recording is a handy feature, but the program is almost impossible to understand.
This guide is easier to understand: http://www.rtl-sdr.com
The SDR-sharp is the most common software: http://www.sdrsharp.com/

I see there are many more options since I used SDR. I like this one: http://www.dxpatrol.pt/index.php/products

Hey Peter,

I'm using SDR-Sharp with this device: Amazon.com

it's the rtl-sdr USB.

SDRs are extremely affordable these days...

Okay, so the transmitter/receiver finally arrived, and I tried RCSwitch advanced example.
I opened the serial monitor, and when I press the button, all that prints is

.........

Am I compiling this incorrectly somehow? It uploads properly... It doesn't seem to be picking up.

Maybe this chip isn't a PT2240 after all.

It might be a different protocol.
At least you can now record a full transmission. I think that previous wav was only a part.

The previous wav was an edited portion of a full recording. I just cut out that one single transmission for ease of study.

Perhaps instead of using some sort of protocol to transmit my signal, such as Serial.write, would it be okay to simply do something like

digitalWrite(pin, HIGH);
delayMillis(200);
digitalWrite(pin, LOW);
delay.....

I know it's not exactly the cleanest code, and probably difficult for timing...

I GOT IT WORKING!

So what I posted before actually worked, with the delays and such.
It just took a lot of tweaking and tuning to get the desired timing.

int button1array[25] = {0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,0,0,0};
int button2array[25] = {0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,1,0,0,0,0};
int button3array[25] = {0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,1,1,0,0,0};
int button4array[25] = {0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,0,1,0};
int button5array[25] = {0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,1,0,0};
int button6array[25] = {0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,1,1,0};
int button7array[25] = {0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0};
const int tx = 2;

void setup()
{
	pinMode(tx, OUTPUT);
	Serial.begin(9600);
}

void loop()
{
	int buttonPressed = Serial.read();
	
	if (buttonPressed == '1')
	{
		for (int i = 0; i<25; i++)
		{
			if (button1array[i] == 1)
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(650);
				digitalWrite(tx, LOW);
				delayMicroseconds(210);
			}
			else
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(210);
				digitalWrite(tx, LOW);
				delayMicroseconds(650);
			}
		}
	}
	
	if (buttonPressed == '2')
	{
		for (int i = 0; i<25; i++)
		{
			if (button2array[i] == 1)
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(650);
				digitalWrite(tx, LOW);
				delayMicroseconds(210);
			}
			else
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(210);
				digitalWrite(tx, LOW);
				delayMicroseconds(650);
			}
		}
	}
	if (buttonPressed == '3')
	{
		for (int i = 0; i<25; i++)
		{
			if (button3array[i] == 1)
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(650);
				digitalWrite(tx, LOW);
				delayMicroseconds(210);
			}
			else
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(210);
				digitalWrite(tx, LOW);
				delayMicroseconds(650);
			}
		}
	}
	if (buttonPressed == '4')
	{
		for (int i = 0; i<25; i++)
		{
			if (button4array[i] == 1)
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(650);
				digitalWrite(tx, LOW);
				delayMicroseconds(210);
			}
			else
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(210);
				digitalWrite(tx, LOW);
				delayMicroseconds(650);
			}
		}
	}
	if (buttonPressed == '5')
	{
		for (int i = 0; i<25; i++)
		{
			if (button5array[i] == 1)
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(650);
				digitalWrite(tx, LOW);
				delayMicroseconds(210);
			}
			else
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(210);
				digitalWrite(tx, LOW);
				delayMicroseconds(650);
			}
		}
	}
	if (buttonPressed == '6')
	{
		for (int i = 0; i<25; i++)
		{
			if (button6array[i] == 1)
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(650);
				digitalWrite(tx, LOW);
				delayMicroseconds(210);
			}
			else
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(210);
				digitalWrite(tx, LOW);
				delayMicroseconds(650);
			}
		}
	}
	if (buttonPressed == '7')
	{
		for (int i = 0; i<25; i++)
		{
			if (button7array[i] == 1)
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(650);
				digitalWrite(tx, LOW);
				delayMicroseconds(210);
			}
			else
			{
				digitalWrite(tx, HIGH);
				delayMicroseconds(210);
				digitalWrite(tx, LOW);
				delayMicroseconds(650);
			}
		}
	}
}

based on what you enter in the Serial monitor, the rf module transmits that signal.
I compared the waveforms in audacity and they are pretty close to each other.

I guess this is solved.

Thanks a lot Peter for you help!

That is bit toggling the most basic way :astonished:
I'm glad it is working :stuck_out_tongue: