How to read the debug output on Linux?

So in our project we use Tx and Rx for the communication network at our Uni. The prof wants us to use two digital pins for debugging.

So I have:

Rx on 5
Tx on 6

I now want to output data to the Tx pin, that I am reading from an analog pin.

So I write

val = analogRead(A0);
analogWrite(6, val) ;

I don't know if this is right. I basically want to measure voltage and write it to pin 6. I know that the read values go from 0 to 1023 and the written values from 0 to 255. So do I have any conversion to make? On the oscilloscope I see that there are values being transmitted. Before when I was using digitalWrite I only got a HIGH value.

Then I want to read the data on Linux and write it in a file. First I have tried

cat -v /dev/ttyUSB0

to see if there is anything being received, but I only get a:

^@^@

Can anyone help me with this or recommend tutorials?

In the end I want to output the values every 30 seconds and write them to a file. I know I will have to program a script then, but at first I want to understand the basics.

Cheers

you can transmit the data using the serial communications, e.g.

val = analogRead(A0);
Serial.println(val);

You can create an extra Serial port using SoftwareSerial and connect that to your PC using a USB-TTL cable.

...R

I can't use a USB cable because it would conflict with the battery. I want to create a State of Charge indicator and therefore discharge the battery until the Arduino dies. I output the data on pin 6 and have to work with that.

could you not use a FDTI serial TTL cable and SoftwareSerial (or hardware serial if you are using a Mega) as suggested by Robin2?

gunjah292:
I can't use a USB cable because it would conflict with the battery.

A USB-TTL cable will not provide any power to an Arduino if you only connect Rx Tx and GND.

...R

Well, I could but the Prof wants me to do it like this. Rx and Tx are already reserved for another communication port. I need to program my own script to read and process the raw data. I am writing a script in python at the moment.

I now need to know what is actually happening here. This is my sketch so far:

#define BatteryIN A1
#define DebugOUT 6

int batteryValue = 0;

void setup() {
  
  Serial.begin(9600);

  pinMode(BatteryIN, INPUT);
  pinMode(DebugOUT, OUTPUT);

}

void loop() {

   batteryValue = analogRead(BatteryIN);
   analogWrite(DebugOUT, batteryValue) ;
   
   Serial.print(batteryValue);

}

Since the value range is an integer from 0 to 1023, what exactly happens when I use analogWrite() to send it to pin 6? Is it being converted to a 0 to 255 value?

have a look at analogwrite which outputs a pWM signal - how do you intend to read this under Linux?

gunjah292:
Well, I could but the Prof wants me to do it like this.

Can you post the precise terms of the Professor's requirement.

In your Original Post you say "The prof wants us to use two digital pins for debugging" and my suggestion to use SoftwareSerial and a USB-TTL converter complies 100% with that,

...R