Welcome to Cockpitbuilders.com. Please login or sign up.

April 19, 2024, 07:53:05 PM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
270 Guests, 0 Users
Members
  • Total Members: 4,154
  • Latest: xyligo
Stats
  • Total Posts: 59,640
  • Total Topics: 7,853
  • Online today: 300
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 270
Total: 270

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

Ardsim and max7219

Started by Ronix77, August 01, 2015, 12:39:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ronix77

Hi guys,
I'm trying to display the value of any getdata() on my max7219 controller but everytime that i start the plugin, the 7 segment display goes in confusion displaying just some segment sometimes very bright.
The problem seems to be linked to the Simstart and simscan function. If i remove these function and assign a value to the integer the max7219 work well.Here is my code:

#include <SPI.h>         
#include <Ethernet.h>
#include <ARDsim.h>
#include "LedControl.h"

byte MAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};// MAC-Address of Arduino
unsigned int XP = 5080;           // port to receive Data from Xplane
byte IP[] = {0, 0, 0, 0};     //IP of this Arduino
LedControl lc1=LedControl(12,11,10,1);


void setup()
  {   
 
SimStart (XP, MAC, IP);
EncoderPort(5, 8, 9,2,1); // Port:22,23,24;  Enc. inputs:36-39;
lc1.shutdown(0,false);
lc1.setIntensity(0,8);
lc1.clearDisplay(0);
EncoderType (2,4,1);
  }

void loop()
  {
    int ones;
    int tens;
    int hundreds;
   
    SimScan();

    int v=GetData(29);
   
    ones=v%10;
    v=v/10;
    tens=v%10;
    v=v/10;
    hundreds=v;

    lc1.setDigit(0,2,(byte)hundreds,false);
    lc1.setDigit(0,1,(byte)tens,false);
    lc1.setDigit(0,0,(byte)ones,false);

}


Any help?
Thank you
737 cockpit builder with Ardsim and X-plane

VladSim

#1
Hi Fabio,

it's not in the ArdSim, and SimStart and SimScan functions are essential.

If your output dataref  #29 is the NAV1  frequency (say 116.05) ,  you should remember that its value is represented in X-Plane as  11605,
i.e. as 5-digit integer,  without decimal point.

So, in your case, if you need only first 3 digits, just devide value by 100:

    int v=GetData(29);
    v=v/100;
   
    ones=v%10; 
    v=v/10;
    tens=v%10;   
    v=v/10;
    hundreds=v;

--------------------------------
I remember you have written to me on email a week ago (we can continue there)

Regards,
Vlad
Arduino interface http://arduino.svglobe.com - easy way to control your home cockpit

Ronix77

Hi Vlad,
i've made a couple of tests and the result is the same.
I've tried with the nav1 sent from x-plane as 11318 and the display goes crazy like the predator clock (remember the movie?). Note that arduino see 116 but this could be a problem of out_1 configuration.
See this video:

https://www.youtube.com/watch?v=jnfuCNcivfU

This video is the max7219 connection test showing everything perfect:

https://www.youtube.com/watch?v=xHVNRIpRQ1M

thank you for your patience.
Have a nice day
737 cockpit builder with Ardsim and X-plane

VladSim

#3
Fabio,

I can see now where your problem is.
Ethernet shield uses SPI on the pin Arduino #10, and  pin #10 should not be used for anything else (as it is noted on the site).

You are using the LedControl library for max7219,  this library also uses SPI to communicate with max. (http://playground.arduino.cc/Main/LedControl)
As I see in your LedControl setup you set pin #10 for SPI.

LedControl lc1=LedControl(12,11,10,1);

So, there is a conflict between Ethernet shield and max7219, and you get messed values sent to max7219.

Try to choose another pin # for LedControl(12, 11, 9, 1);

And btw, when you take "modulo" for "ones" in your code you shoud do:
ones = v%10;   (not ones = v%100;.  else you got 2-digit value for "ones")
---------------------------

I will add support of 7-seg LEds in ArdSim library soon (support of 74hc595 registers)

Regards.
Arduino interface http://arduino.svglobe.com - easy way to control your home cockpit

Ronix77

Oh Vlad, thank you very much, now it function!
I've completely changed the max7219 pins using 7,8,9 and the displays looks steady and the response is
immediate as i change the value with the encoder.

I continue my project using the max7219; as soon as you implement the new support for the 74hc595, i will decide if migrate on this chip or continue with mine...

Thank you again

Fabio
737 cockpit builder with Ardsim and X-plane

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate