Hi
I have encountered some confusion in a my program I have used a sensor and received data binaire and I want to convert it to ASCII code .i try to search any commande but Like(StringConstructor /BinToChar .... )but they didn't help me or didn't know how to hire them
int arr[8]; int i = 0;
int ldr = A0;
void setup() {
Serial.begin(9600);
Serial.println(" ready for a recevoire ");
Serial.println(" ");
}
void loop()
{
for (int i = 0; i < 8; i++) {
if (analogRead(ldr) >= 800)//
{
arr[i] = 1;
}
else {
arr[i] = 0;
}
Serial.print(arr[i]);
while(i==7){
Serial.print('\r');
}
i++;
delay(200);}}
I see lots of questions in your code. Yes, it should compile and run, but I'll bet that your resulting array is either all 1's or all 0's.
The Uno runs at 16 mHz, so loop() would run approximately every 62.5 ns or about 117,000 times per second. (Depending on what code is in the loop function). Is your data on A0 really that fast?
How do you know when the data stream starts? If your data is slower than 117Kb/sec (likely), then you need to read the A0 line at the same period
light__fidelity:
Hi
I have encountered some confusion in a my program I have used a sensor and received data binaire and I want to convert it to ASCII code .i try to search any commande but Like(StringConstructor /BinToChar .... )but they didn't help me or didn't know how to hire them
you CONSISTENTLY seem to be asking the SAME question.
I already proposed to you a solution here
you need to read up MORE on how serial (RS232) transmission is generated. there is loads of material out there.
An alternative as a proof of concept is that you could us the ACTUAL rx/tx line on your arduino and hook up an external circuit. something like this maybe:
then all you need is to use the Serial functions (Begin, Read, Print) to read/write data to/from your arduino (assuming you are using a baudrate that is slow enough for the LED to react correctly)
SteveMann:
The Uno runs at 16 mHz, so loop() would run approximately every 62.5 ns or about 117,000 times per second. (Depending on what code is in the loop function). Is your data on A0 really that fast?
sp. "16MHz"
I don't know where you magicked the other numbers from.
sherzaad:
void rx_byte(void)
{
uint8_t data_val;
uint8_t cnt;
uint8_t err;
/* pin as input pull up */
RX_PIN_INPUT_PULLUP();
while(1)
{
data_val = 0U;
err = 0U;
/* while pin is high /
while(analogRead(ldr) >= 800);
/ 1.5 bit delay /
delay(DELAY_US_1_5_BIT);
/ get byte /
for(cnt = 0U ; cnt < 8U ; cnt++)
{
data_val >>= 1;
if(analogRead(ldr) >= 800) data_val |= 0x80;
/ 1 bit delay /
delay(DELAY_US_1_0_BIT);
}
/ stop bit error low */
if(analogRead(ldr) < 800)
{
err = 1;
}
}
are this code for generating start bit and stop bit and where i put it in my main program ,
cordenalemnt
Yet more here
I think someone is about to get a smacked botty.
SteveMann:
but I'll bet that your resulting array is either all 1's or all 0's.
The Uno runs at 16 mHz, so loop() would run approximately every 62.5 ns or about 117,000 times per second.
How do you know when the data stream starts? If your data is slower than 117Kb/sec (likely), then you need to read the A0 line at the same period
yes my resulting array is either all 1's or all 0's.
shall you explains Where did those numbers come from (62.5 ns or about 117,000 times per second. )?
i'm reserch in net how to introduce start bit and stop bit
thnks Sir
@light__fidelity
You are hereby sentenced to 7 days holiday from the forum.
You crimes were as follows.
Unable to comply with moderator requests.
Multiple accounts
Cross posting.
Wasting peoples time and efforts to help you.
I am prepared to reduce the sentence if you READ THIS post and demonstrate that you understand it.
Bob