IR remote control-Kogna

Moderators: TomKerekes, dynomotion

katiefangffs
Posts: 14
Joined: Sat Feb 17, 2024 9:57 am

IR remote control-Kogna

Post by katiefangffs » Mon Feb 19, 2024 3:13 am

Hi, I am testing a stepper motor using the Kogna board with an ir control. The ir remote is decoded to Hexadecimal codes such as FF38c7, FFB847, and so on. However, once I connet the ir to the board and run the code, it seems like the 24 bits are not read into the receiver so the output looks
like with every button I press on the remote.

> Output:
> Bit 0: 0
> Bit 1: 1
> Bit 2: 1
> Bit 3: 1
> Bit 4: 1
> Bit 5: 1
> Bit 6: 1
> Bit 7: 1
> Bit 8: 1
> Bit 9: 1
> Bit 10: 1
> Bit 11: 1
> Bit 12: 1
> Bit 13: 1
> Bit 14: 1
> Bit 15: 1
> Bit 16: 1
> Bit 17: 1
> Bit 18: 1
> Bit 19: 1
> Bit 20: 1
> Bit 21: 1
> Bit 22: 1
> Bit 23: 1
> Read IR Command: 0x7FFFFF
>
The code I am using is:
#include "KMotionDef.h"

// Define IR Hexadecimal codes for each button
#define BUTTON_UP 0xFF38C7
#define BUTTON_DOWN 0xFFB847
#define BUTTON_ONOFF 0xFFF00F
#define BUTTON_1 0xFF20DF
#define BUTTON_2 0xFFA05F
#define BUTTON_3 0xFF609F
#define BUTTON_4 0xFF7887
#define BUTTON_5 0xFFE01F
#define BUTTON_6 0xFF10EF
#define BUTTON_7 0xFF906F
#define BUTTON_8 0xFFD827

int currentAxis = -1; // default
SetBitDirection15=0; //set bit 15 as input



/* Declare function prototypes
void ProcessCommand(unsigned int IRCommand);
unsigned int ReadIRCommand(void);
int ReadBit(int pin); */

// Function reads in binary value and saves in var. IRCommand
unsigned int ReadIRCommand() {
unsigned int IRCommand = 0; // Initialize to 0
int i; // Declare loop variable
int bitValue;

while(ReadBit(15)==1); //wait for something to Start, 1=high, 0=low

for (i = 0; i < 24; i++) {
bitValue = ReadBit(15); // Read a single bit
Delay_sec(0.2);
printf("Bit %d: %d\n", i, bitValue); // Debugging line
IRCommand = (IRCommand << 1) | bitValue; //binary -> hexadecimal

}

printf("Read IR Command: 0x%X\n", IRCommand);

return IRCommand;
}

// Function to process command
void ProcessCommand(unsigned int IRCommand) {
switch (IRCommand) {
case BUTTON_1:
if (currentAxis != -1) DisableAxis(currentAxis);
EnableAxis(2);
currentAxis = 2;
break;
case BUTTON_UP:
if (currentAxis != -1) MoveRel(currentAxis, 10);
break;
case BUTTON_DOWN:
if (currentAxis != -1) MoveRel(currentAxis, -10);
break;
default:
// Handle unknown command
break;
}
}

int main() {
while (1) {
unsigned int IRCommand = ReadIRCommand();
// Check if the read command is not the idle signal
//if(IRCommand != 0xFFFFFFFF) {
ProcessCommand(IRCommand);
Delay_sec(1);
}
return 0;
}
//}

Thank you.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: IR remote control-Kogna

Post by TomKerekes » Mon Feb 19, 2024 3:43 am

Hi Katie,

What kind of IR Control do you have? What is the timing?

See this demo video:



This IR Control output a sequence of state changes with "long" or "short" times between change to indicate a 1 or 0. If the time was less than 0.001 seconds a 0 was indicated. If longer a 1 was indicated.

Your code appears to just sample every 0.2 seconds (plus whatever time the printout takes) so the data transmission is probably way over by the time of the first 0.2 second delay.

I can't locate the code used in the demo from years ago but here is a screen shot from the video showing how the code is determined.

The KFLOP Time slices are 90us. With just one User Thread running running the next time slice will occur 180us later. So if the transition occurs after 6 Time Slice it is considered to be a long time.
ReadCode.png


HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

katiefangffs
Posts: 14
Joined: Sat Feb 17, 2024 9:57 am

Re: IR remote control-Kogna

Post by katiefangffs » Tue Feb 20, 2024 5:48 am

Hi Tom,

I've been exploring the UART functionality as described on the website and have a question regarding the use of input pin IO44 for UART communication. After adjusting my hardware setup based on the guidance provided and implementing the sample receiving code available on the site, I've encountered some inconsistencies in the output.

When pressing the same button on my IR remote, the output varies significantly at times. Moreover, different buttons occasionally yield identical outputs. Here's an example of the output from pressing a single button:

0
0
F8
0
0
F8
0
0
F8
0
0
F8
0
0
F8
0
0
F8
0
0
F8
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
E0
0
0
F8

I'm uncertain if this behavior is expected or indicative of an issue.

Following your previous suggestion, I incorporated the timing function, which did improve the output to some extent. However, the results still aren't as consistent as expected, indicating a need for further debugging.

Would switching my approach to utilize a dedicated UART pin instead of IO44 potentially bypass these inconsistencies, thereby streamlining the process and eliminating the need for extensive debugging?

Thank you.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: IR remote control-Kogna

Post by TomKerekes » Tue Feb 20, 2024 5:47 pm

Do didn’t tell us the IR sensor you are using or the protocol and timing.

I don’t see how a UART would ever work with a sensor like used in the video as they are completely different protocols.
Regards,

Tom Kerekes
Dynomotion, Inc.

katiefangffs
Posts: 14
Joined: Sat Feb 17, 2024 9:57 am

Re: IR remote control-Kogna

Post by katiefangffs » Wed Feb 21, 2024 2:06 am

Hi, I'm currently using a 38kHz YwRobot IR receiver, but unfortunately, the IR remote lacks specifications. You can find the specific IR receiver used at this link: https://www.amazon.com.au/YwRobot-IR-Co ... B07B482GR4.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: IR remote control-Kogna

Post by TomKerekes » Wed Feb 21, 2024 4:19 pm

You would need to know the protocol and timing to interface to it. Is there a reason to use a remote you don't have information on?

I think the 38KHz is probably the carrier frequency that doesn't really have anything to do with the protocol.

Do you have an oscilloscope to observe what sequence is being transmitted.

You might use Kogna as an oscilloscope to sample the signal every WaitNextTimeSlice (180us) into a memory array and then afterwards print it out to try to reverse engineer what it does.
Regards,

Tom Kerekes
Dynomotion, Inc.

katiefangffs
Posts: 14
Joined: Sat Feb 17, 2024 9:57 am

Re: IR remote control-Kogna

Post by katiefangffs » Thu Feb 22, 2024 9:47 am

Hi,

regarding the timing you mentioned, is it possible to test it given that remote information isn't referable?

I've managed to get the code working by connecting the IR receiver to an Arduino Uno board at 3.3V, with the RX and TX pins linked to the UART on Kogna. Would this setup pose any issues, especially considering I'm operating a 5-axis machine with 6 motors? I'm concerned about potential delays in signal transmission or any circuit-related issues.

Thank you.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: IR remote control-Kogna

Post by TomKerekes » Thu Feb 22, 2024 4:27 pm

Hi Katie,
regarding the timing you mentioned, is it possible to test it given that remote information isn't referable?
See my previous post.

I've managed to get the code working by connecting the IR receiver to an Arduino Uno board at 3.3V, with the RX and TX pins linked to the UART on Kogna. Would this setup pose any issues, especially considering I'm operating a 5-axis machine with 6 motors? I'm concerned about potential delays in signal transmission or any circuit-related issues.
What code is running in the Arduino to decode it? It must know the protocol.

Since a human is pushing the buttons I wouldn't think an Arduino delays would ever be significant.
Regards,

Tom Kerekes
Dynomotion, Inc.

katiefangffs
Posts: 14
Joined: Sat Feb 17, 2024 9:57 am

Re: IR remote control-Kogna

Post by katiefangffs » Sat Feb 24, 2024 2:56 pm

Hi, for your reference, these are the code I am currently using:

*Arduino for decoding purpose:
#include <IRremote.h>

const int IR_RECEIVER_PIN = 8; // Define the IR receiver pin
const unsigned long IDLE = 0xFFFFFFFF; // Define the value to ignore

IRrecv irrecv(IR_RECEIVER_PIN); // Create an instance of IRrecv
decode_results results; // Create an instance of decode_results to store the decoding results

void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
irrecv.enableIRIn(); // Enable the IR receiver
}

void loop() {
if (irrecv.decode(&results)) {
unsigned long value = results.value;

if (value != IDLE) {
Serial.print(value, HEX); // Send the hexadecimal value
Serial.print("\r\n"); // Explicitly send carriage return and newline
}

irrecv.resume(); // Prepare to receive the next value
}
}


*Kmotion code that reads the Arduino value from the Uart pins:
#include "KMotionDef.h"

// Define IR Hexadecimal codes for each button
#define BUTTON_UP 0xFF38C7
#define BUTTON_DOWN 0xFFB847
#define BUTTON_ONOFF 0xFFF00F
#define BUTTON_1 0xFF20DF
#define BUTTON_2 0xFFA05F
#define BUTTON_3 0xFF609F
#define BUTTON_4 0xFF7887
#define BUTTON_5 0xFFE01F
#define BUTTON_6 0xFF10EF
#define BUTTON_7 0xFF906F
#define BUTTON_8 0xFFD827

int currentAxis = -1; // Global variable to track the current enabled axis

// Function to process command
void ProcessCommand(unsigned int IRCommand) {
switch (IRCommand) {
case BUTTON_1:
if (currentAxis != -1) DisableAxis(currentAxis); // Disable the current axis if one is enabled
EnableAxis(2); // Enable Axis 2 for this example
currentAxis = 2; // Set the current axis to 2
printf("Button 1 pressed. Axis 2 enabled.\n");
break;
case BUTTON_UP:
if (currentAxis != -1) MoveRel(currentAxis, 9600);
printf("Button up pressed. moved positive 9600.\n");
break;
case BUTTON_DOWN:
if (currentAxis != -1) Move(currentAxis, -9600);
printf("Button down pressed. moved negative 9600.\n");
break;
default:
// Handle unknown command
break;
}
}


// Function to receive a character from RS232
unsigned char ReceiveChar() {
// wait for data in buffer
while ((FPGA(RS232_STATUS) & RS232_DATA_READY) == 0);
return FPGA(RS232_DATA);
}

// Function to receive a full command (until newline)
unsigned int ReceiveCommand() {
unsigned int command = 0;
unsigned char ch;
do {
ch = ReceiveChar();
if (ch >= '0' && ch <= '9') {
command = (command << 4) | (ch - '0');
} else if (ch >= 'A' && ch <= 'F') {
command = (command << 4) | (ch - 'A' + 10);
} else if (ch >= 'a' && ch <= 'f') {
command = (command << 4) | (ch - 'a' + 10);
}
// Repeat until newline or carriage return
} while (ch != '\n' && ch != '\r');

return command;
}

void main() {
SetBitDirection(45,1);
FPGA(RS232_BAUD_REG) = RS232_BAUD_9600;
// FPGA(KAN_TRIG_REG) = 1; // enable Kanalog to get RS232 working


for (;;) {
//printf("Waiting for command...\n"); // Debugging line
unsigned int IRCommand = ReceiveCommand(); // Receive a full command
ProcessCommand(IRCommand); // Process the received IR command
}
}


This set of codes runs perfectly, enabling the axis and moving the stepper motor. Yet, it necessitates an additional Arduino board for operation. I'm wondering if this could possibly be achieved by the Kogna board independently , potentially through either the UART pins or the JP7 pins.


Thank you.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: IR remote control-Kogna

Post by TomKerekes » Sat Feb 24, 2024 7:59 pm

You aren’t showing the Arduino code that decodes the IR sensor. You would need to understand the IRrecv class to understand what it is doing.

Please post any code using the <\> code tags to make your posts more readable.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply