Jump to content
hemangjoshi37a

Weird characters in serial monitor

Recommended Posts

Dear developers,

I am simply using

Serial.println();

command, but I get some weird characters in the serial port display window.

Code : 

#include <Wire.h>
// HIH6130 I2C address is 0x27(39)
#define Addr 0x27

int tzero = 196;
int tspan = 17;
int hzero = 196;
int hspan = 17;

void setup()
{
Wire.setModule(1);
Wire.begin();
pinMode(P1_3,OUTPUT);
pinMode(P1_2,OUTPUT);
pinMode(P1_6,OUTPUT);
Serial.begin(9600);
Serial.println("OK");
delay(300);
}

void loop()
{
  
  unsigned int data[4];

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select data register
  Wire.write(0x00);
  // Stop I2C Transmission
  Wire.endTransmission();
  // Request 4 bytes of data
  Wire.requestFrom(Addr, 4);

  // Read 4 bytes of data
  // humidity msb, humidity lsb, temp msb, temp lsb
  if (Wire.available() == 4)
  { data[0] = Wire.read();
    data[1] = Wire.read();
    data[2] = Wire.read();
    data[3] = Wire.read();
  }

  // Convert the data to 14-bits
  float humidity = ((((data[0] & 0x3F) * 256) + data[1]) * 100.0) / 16383.0;
  float temp = ((data[2] * 256) + (data[3] & 0xFC)) / 4;
  float  cTemp = (temp / 16384.0) * 165.0 - 40.0;

  // Output data to serial monitor
  Serial.print("Relative Humidity :");
  Serial.println(humidity);
  Serial.println(" %RH");
  Serial.print("Temperature in Celsius :");
  Serial.println(cTemp);
  Serial.println(" C");
  Serial.println("=============================================================== ");

  int VcTemp = map(cTemp, -5, 125, tzero, tspan );
  int vhumidity = map (humidity, 0, 100, hzero, hspan);

  analogWrite(P1_2, VcTemp);
  analogWrite(P1_6, vhumidity);

  delay(1000);
}

Serial Output : 

Quote

������������ 

(in one single line, means it keeps  printing these characters in just one line on and on.picture : 

Quote

Screenshot : 

59c0ca7a90fff_Screenshotfrom2017-09-1913-08-25.thumb.png.784949bb18e4ab2d2a6a5fd9b4f4a9fb.png

 

Thax.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×