STM32f103c8t6 (Blue Pill) IR Communication

What are you developing?
Post Reply
Melvin
Posts: 3
Joined: Thu Mar 04, 2021 7:50 am

STM32f103c8t6 (Blue Pill) IR Communication

Post by Melvin »

Hi developer,

I am working on a project to transfer information from one STM32F103C8T6 (BluePill) to another via infrared (IR) receiver and transmitter.
However, I still cannot find a ready use library yet after browsing for it for a couple of days.
May I ask for a suggestion of any ready-use library for IR communication between these two STM32F1 board using Arduino IDE?
Thank you very much in advance.

Best regards
Melvin
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32f103c8t6 (Blue Pill) IR Communication

Post by stevestrong »

G**gle is your friend: https://github.com/ukw100/IRMP
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32f103c8t6 (Blue Pill) IR Communication

Post by ag123 »

this is for 'advanced' users, if you read
rm0008

stm32 usart can do IRDA SIR , read section 27 USART -> 27.3 IrDA SIR ENDEC block
'nobody has tried it here', at least not publicly.

so if you feel adventurous you can try playing with that and perhaps document that in a forum post/thread here.
i'd imagine it is quite possible to use cheap ir transmitters and receivers to test it
e.g. those TCRT5000 types
https://www.vishay.com/docs/83760/tcrt5000.pdf
https://www.aliexpress.com/wholesale?ca ... t=tcrt5000

the manual mentions :
The IrDA mode is selected by setting the IREN bit in the USART_CR3 register. In IrDA
mode, the following bits must be kept cleared:
LINEN, STOP and CLKEN bits in the USART_CR2 register,
SCEN and HDSEL bits in the USART_CR3 register.
this just means in addition to playing with hardware serial e.g. Serial1, you'd need to do direct register accesses to set that up accordingly.

note that one of those things that's rather hard to do is the signal receive conditioning etc. hence the receiver would be sensitive to ambient light and other IR interference. i'd guess the 'proper' ones would do some form of AGC (automatic gain control) to get better signals. for tests without all that conditioning, i'd guess it would be necessary to use some kind of cover/shielding etc to get a better signal.

normally those IR photo diodes produce very little current, so it'd be necessary to use a transistor to amplify that.

Code: Select all

  
  vdd (3v3) --- |< (IR photo diode) --- + --- resistor  --- | gnd
                                        + --- base of transistor for amplification  
my thoughts is that this little cheap hack may work, connect your photo diode between vdd (3v3) and the serial pin e.g. PA10 (RX).
then that resistor would need to be a variable resistor so that you can tune the turn on threshold for the 'high' logic level
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32f103c8t6 (Blue Pill) IR Communication

Post by ag123 »

for something more 'advanced', and that you are not using the adc after all, i'd imagine it may be possible to read the photodiode as analog voltages, process it digitally (dsp), then in the code, you could set pa10 high or low (i'm not too sure if that'd interfere with the uart) based on the processed signal.
this would be elaborate AGC (automatic gain control), and it may be possible to do 'impossible' filtering to deal with ambient light / interference etc.
this may after all be feasible as serial speeds is 115200 bps

but even without AGC, the hardware serial supported IRDA SIR is attractive. as IR comms simply means Serial.write(data) and at the receiving end it is Serial.read(data) and this is the (stm32duino) core itself.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32f103c8t6 (Blue Pill) IR Communication

Post by stevestrong »

There are examples for Tx and Rx using SPL here: https://github.com/JoeMerten/Stm32/tree ... USART/IrDA
You may try to adapt them to actual STM core.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: STM32f103c8t6 (Blue Pill) IR Communication

Post by mrburnette »

Melvin wrote: Thu Mar 04, 2021 8:00 am ...
However, I still cannot find a ready use library yet after browsing for it for a couple of days.
This is the lib most often associated with Arduino IrDA:
http://www.righto.com/search/label/ir

Above may require some effort to convert to STM32, do not know.

IR remote control (not data transmission) is so simple, it can be done on an UNO without interrupts!

If Ir control-only is desired, this is often a better approach:
https://create.arduino.cc/projecthub/el ... ino-1e6bc8

The entire ambient light issue/swamping effect is eliminated with this type of sensor:
https://www.adafruit.com/product/157

For high-bandwidth, simplex communication through air, lasers are preferred.
https://www.researchgate.net/publicatio ... munication
The main goal of this paper is to propose a simple and low-cost microcontroller-based laser communication link. To demonstrate that laser communication is a viable and efficient means for transmitting data, a transceiver capable of transfer rates of approximately 0.7 kB/s is prototyped. The hardware used for the transceiver consists of Commercial Off-The-Shelf (COTS) lasers, photodiodes, and the Arduino Mega 2560 which is an open-source and easy-to-use microcontroller-based platform intended for making interactive projects. A Graphical-User-Interface (GUI) utilizing the Meteor framework is developed to facilitate the communication between the user and transceiver. The developed transceiver prototype is capable of receiving and transmitting data at significant ranges with no loss of information. Furthermore, stable and secure communication is achieved through several mechanisms developed to manage simultaneous sending and receiving, in addition to detecting physical interruptions during transmission. The design setup is scalable and with further development can be transformed into a fiber-optic transmission system. Due to its nature, laser communication is very secure and can provide a safe and private communication link. Overall, this paper demonstrates how laser communication can be an economical, durable, and effective means of information transfer.
Transceiver-setup.png
Transceiver-setup.png (61.93 KiB) Viewed 7118 times
Melvin
Posts: 3
Joined: Thu Mar 04, 2021 7:50 am

Re: STM32f103c8t6 (Blue Pill) IR Communication

Post by Melvin »

Thank you for the suggestions everyone,

I am new to STM32 and it is absolutely different from simple Arduino board. I am now studying how to code using the embedded C in STM32CubeIDE and this one is also very challenging.
Meanwhile, I am writing the some codes still in Arduino IDE, using SoftwareSerial.h
My Transmitter definitely sends something, but I have difficulty in showing the transmitted value in 'Byte' on the receiver board. (FYI, currently still using 2 Blue Pill, each connected to IR receiver and IR transmitter)
Here is the code for Transmitter:

Code: Select all

#include <SoftwareSerial.h>
#define RX PB3
#define TX PA2

SoftwareSerial port = SoftwareSerial(RX, TX);

void setup()  
{
     port.begin(9600);
}

void loop() 
{ 
  port.println("Hello World");
  delay(200);

}
And here is the code for Receiver:

Code: Select all

#include <SoftwareSerial.h>
#define RX PA3
#define TX PB3

SoftwareSerial port = SoftwareSerial(RX,TX,false);

void setup()  
{
     port.begin(9600);
     Serial.begin(9600);
     Serial.println("Start Listening...");
}

void loop() 
{ 
  if(port.available())
  {
    char inByte = port.read();
    Serial.println(inByte);
  }
}
I wonder what is missing in the receiver side.
I program this board using UART pin PA9 and PA10 of the Blue Pill with cross connection (RX, TX) with my USB to TTL module (RX is now PA9 and TX is now PA10).
After I download the program to the Blue Pill, I change my receiver's RX TX connection from cross to parallel (RX is now PA10, and TX is now PA9).
This should show me the Byte value in my Arduino IDE Serial monitor, shouldn't it?
Last edited by Melvin on Fri Mar 19, 2021 7:06 am, edited 1 time in total.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32f103c8t6 (Blue Pill) IR Communication

Post by ag123 »

normally for 'blue pill' (stm32f103c8) type boards, it is more convenient to use usb serial on the usb side and HardwareSerial for the pins pa9 and pa10 (uart1).
i've an example in libmaple core showing how to funnel data between usb-serial and hardware-serial (e.g. uart1, pa9, pa10 )
https://github.com/rogerclarkmelbourne/ ... -w-signals

the codes can be adapted to be used on the official core except for the DTR, RTS signal handling part, the part that does a usbsetuphook()
https://github.com/rogerclarkmelbourne/ ... ls.ino#L37
probably won't work on the official core

the codes that does most that work funneling the data is this section
the api between libmaple vs official core is slightly different, so do review the docs.
https://github.com/stm32duino/wiki/wiki ... wareserial

Code: Select all

#include <HardwareSerial.h>
uint8 ledPin = LED_BUILTIN;
HardwareSerial Serial1(PA10, PA9); // note this is for the official core definition

void setup() {
   pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH);
  Serial.begin(); //usb serial
  Serial1.begin(115200); /hardware serial (uart)
}

void loop() {
	if(Serial1.available()) {
		digitalWrite(ledPin, HIGH); // blink the led for traffic
		while(Serial1.available()) {
			char c = Serial1.read();
			Serial.write(c);
		}
		digitalWrite(ledPin, LOW);
	}

	if(Serial.available()) {
		digitalWrite(ledPin, HIGH); // blink the led for traffic
		while(Serial.available()) {
			char c = Serial.read();
			Serial1.write(c);
		}
	}
	digitalWrite(ledPin, LO)
	delay(1);
}	
to use the IR features for the hardware uart, it would take in addition a direct register access to set it as like discussed prior.
i'd imagine that to be a tcrt5000 type of device, but i've never tried it prior
https://www.vishay.com/docs/83760/tcrt5000.pdf
https://www.aliexpress.com/wholesale?ca ... t=tcrt5000

if you do get success with that do update this thread ;)
SIR is quite a 'big deal' as if you remember the old palm pilot days, sir is used to 'beam' business cards and other data between devices/host.
soon after wifi and later bluetooth dominated the scene which doesn't requires a line of sight connection
if it works well, this is still useful as a wireless data exchange means on stm32 devices
Post Reply

Return to “Projects”